mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-08-08 14:55:17 +00:00
Make butlast[0] consistent with rest (#6483)
butlast[0] now returns the input list unchanged. Fixes: #5833
This commit is contained in:
parent
a51191d334
commit
2c38c8351b
@ -87,7 +87,8 @@ exports.butlast = function(source,operator,options) {
|
|||||||
source(function(tiddler,title) {
|
source(function(tiddler,title) {
|
||||||
results.push(title);
|
results.push(title);
|
||||||
});
|
});
|
||||||
return results.slice(0,-count);
|
var index = count === 0 ? results.length : -count;
|
||||||
|
return results.slice(0,index);
|
||||||
};
|
};
|
||||||
exports.bl = exports.butlast;
|
exports.bl = exports.butlast;
|
||||||
|
|
||||||
|
@ -371,6 +371,7 @@ Tests the filtering mechanism.
|
|||||||
expect(wiki.filterTiddlers("[sort[title]reverse[]]").join(",")).toBe("TiddlerOne,Tiddler Three,one,hasList,has filter,filter regexp test,a fourth tiddler,$:/TiddlerTwo,$:/ShadowPlugin");
|
expect(wiki.filterTiddlers("[sort[title]reverse[]]").join(",")).toBe("TiddlerOne,Tiddler Three,one,hasList,has filter,filter regexp test,a fourth tiddler,$:/TiddlerTwo,$:/ShadowPlugin");
|
||||||
expect(wiki.filterTiddlers("[sort[title]reverse[x]]").join(",")).toBe("TiddlerOne,Tiddler Three,one,hasList,has filter,filter regexp test,a fourth tiddler,$:/TiddlerTwo,$:/ShadowPlugin");
|
expect(wiki.filterTiddlers("[sort[title]reverse[x]]").join(",")).toBe("TiddlerOne,Tiddler Three,one,hasList,has filter,filter regexp test,a fourth tiddler,$:/TiddlerTwo,$:/ShadowPlugin");
|
||||||
expect(wiki.filterTiddlers("[sort[title]butlast[]]").join(",")).toBe("$:/ShadowPlugin,$:/TiddlerTwo,a fourth tiddler,filter regexp test,has filter,hasList,one,Tiddler Three");
|
expect(wiki.filterTiddlers("[sort[title]butlast[]]").join(",")).toBe("$:/ShadowPlugin,$:/TiddlerTwo,a fourth tiddler,filter regexp test,has filter,hasList,one,Tiddler Three");
|
||||||
|
expect(wiki.filterTiddlers("[sort[title]butlast[0]]").join(",")).toBe("$:/ShadowPlugin,$:/TiddlerTwo,a fourth tiddler,filter regexp test,has filter,hasList,one,Tiddler Three,TiddlerOne");
|
||||||
expect(wiki.filterTiddlers("[sort[title]butlast[2]]").join(",")).toBe("$:/ShadowPlugin,$:/TiddlerTwo,a fourth tiddler,filter regexp test,has filter,hasList,one");
|
expect(wiki.filterTiddlers("[sort[title]butlast[2]]").join(",")).toBe("$:/ShadowPlugin,$:/TiddlerTwo,a fourth tiddler,filter regexp test,has filter,hasList,one");
|
||||||
expect(wiki.filterTiddlers("[sort[title]butlast[11]]").join(",")).toBe("");
|
expect(wiki.filterTiddlers("[sort[title]butlast[11]]").join(",")).toBe("");
|
||||||
expect(wiki.filterTiddlers("[sort[title]butlast[x]]").join(",")).toBe("$:/ShadowPlugin,$:/TiddlerTwo,a fourth tiddler,filter regexp test,has filter,hasList,one,Tiddler Three");
|
expect(wiki.filterTiddlers("[sort[title]butlast[x]]").join(",")).toBe("$:/ShadowPlugin,$:/TiddlerTwo,a fourth tiddler,filter regexp test,has filter,hasList,one,Tiddler Three");
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
created: 20140410103123179
|
created: 20140410103123179
|
||||||
modified: 20150203191930000
|
modified: 20220226043344258
|
||||||
tags: [[Filter Operators]] [[Order Operators]]
|
tags: [[Filter Operators]] [[Order Operators]]
|
||||||
title: butlast Operator
|
title: butlast Operator
|
||||||
type: text/vnd.tiddlywiki
|
type: text/vnd.tiddlywiki
|
||||||
@ -10,4 +10,6 @@ op-parameter: an integer, defaulting to 1
|
|||||||
op-parameter-name: N
|
op-parameter-name: N
|
||||||
op-output: all but the last <<.place N>> input titles
|
op-output: all but the last <<.place N>> input titles
|
||||||
|
|
||||||
|
<<.from-version "5.2.2">> The <<.op butlast>> operator returns the input list unchanged if <<.place N>> is 0. This is consistent with the behaviour of the [[rest Operator]].
|
||||||
|
|
||||||
<<.operator-examples "butlast">>
|
<<.operator-examples "butlast">>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
created: 20150118134611000
|
created: 20150118134611000
|
||||||
modified: 20150118183143000
|
modified: 20220226043344258
|
||||||
tags: [[butlast Operator]] [[Operator Examples]]
|
tags: [[butlast Operator]] [[Operator Examples]]
|
||||||
title: butlast Operator (Examples)
|
title: butlast Operator (Examples)
|
||||||
type: text/vnd.tiddlywiki
|
type: text/vnd.tiddlywiki
|
||||||
@ -7,5 +7,6 @@ type: text/vnd.tiddlywiki
|
|||||||
<<.using-days-of-week>>
|
<<.using-days-of-week>>
|
||||||
|
|
||||||
<<.operator-example 1 "[list[Days of the Week]butlast[]]">>
|
<<.operator-example 1 "[list[Days of the Week]butlast[]]">>
|
||||||
<<.operator-example 2 "[list[Days of the Week]butlast[2]]">>
|
<<.operator-example 2 "[list[Days of the Week]butlast[0]]">>
|
||||||
<<.operator-example 3 "A B C D E F G H I J K L M +[butlast[7]]">>
|
<<.operator-example 3 "[list[Days of the Week]butlast[2]]">>
|
||||||
|
<<.operator-example 4 "A B C D E F G H I J K L M +[butlast[7]]">>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
created: 20150118134611000
|
created: 20150118134611000
|
||||||
modified: 20150123211722000
|
modified: 20220226043344258
|
||||||
tags: [[rest Operator]] [[Operator Examples]]
|
tags: [[rest Operator]] [[Operator Examples]]
|
||||||
title: rest Operator (Examples)
|
title: rest Operator (Examples)
|
||||||
type: text/vnd.tiddlywiki
|
type: text/vnd.tiddlywiki
|
||||||
@ -7,5 +7,6 @@ type: text/vnd.tiddlywiki
|
|||||||
<<.using-days-of-week>>
|
<<.using-days-of-week>>
|
||||||
|
|
||||||
<<.operator-example 1 "[list[Days of the Week]rest[]]">>
|
<<.operator-example 1 "[list[Days of the Week]rest[]]">>
|
||||||
<<.operator-example 2 "[list[Days of the Week]rest[3]]">>
|
<<.operator-example 2 "[list[Days of the Week]rest[0]]">>
|
||||||
<<.operator-example 3 "Z Y X W V U T S R Q P O +[rest[5]]">>
|
<<.operator-example 3 "[list[Days of the Week]rest[3]]">>
|
||||||
|
<<.operator-example 4 "Z Y X W V U T S R Q P O +[rest[5]]">>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user