Category talk:Wren-seq: Difference between revisions
Content added Content deleted
(→Source code: Fixed a potential bug in Stack.pop() method.) |
(Added Seq.hasAdjDups method.) |
||
Line 18: | Line 18: | ||
return true |
return true |
||
} |
} |
||
// Returns true if any adjacent elements of the sequence are duplicates, false otherwise. |
|||
static hasAdjDup(s) { |
|||
isSeq_(s) |
|||
var iter = s.iterate(null) |
|||
if (!iter) return false |
|||
var prev = s.iteratorValue(iter) |
|||
while (iter = s.iterate(iter)) { |
|||
var next = s.iteratorValue(iter) |
|||
if (next == prev) return true |
|||
prev = next |
|||
} |
|||
return false |
|||
} |
|||
// Returns a new 'lazy' sequence that iterates only the last 'count' elements of |
// Returns a new 'lazy' sequence that iterates only the last 'count' elements of |
||
// the original sequence. |
// the original sequence. |