当前位置: 首页 > 文档资料 > Lazy.js 英文文档 >

last

优质
小牛编辑
135浏览
2023-12-01

Creates a new sequence comprising the last N elements of this sequence, OR (if N is undefined) simply returns the last element of this sequence.

Signature

Sequence.last = function(count) { /*...*/ }
Sequence.last = function last(count) {
  if (typeof count === "undefined") {
return this.reverse().first();
  }
  return this.reverse().take(count).reverse();
}
NameType(s)Description
countnumber?

The number of items to take from the end of the sequence.

returns*

The new sequence (or the last element from this sequence if no count was given).

Examples

Lazy([1, 2, 3]).last()                 // => 3
Lazy([1, 2, 3]).last(2)                // sequence: [2, 3]
Lazy([1, 2, 3]).filter(isEven).last(2) // sequence: [2]