mirror of
https://github.com/vale981/tridactyl
synced 2025-03-06 01:51:40 -05:00
itertools: add tail
This commit is contained in:
parent
4981a3618e
commit
ff69b7e8a1
1 changed files with 11 additions and 0 deletions
|
@ -6,6 +6,17 @@ export function head(iter) {
|
||||||
else return result.value
|
else return result.value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Get the last item of an array or iterable */
|
||||||
|
export function tail(iter) {
|
||||||
|
if (Array.isArray(iter)) {
|
||||||
|
return iter[iter.length - 1]
|
||||||
|
} else {
|
||||||
|
let last
|
||||||
|
for (last of iter) {}
|
||||||
|
return last
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Zip some arrays together
|
/** Zip some arrays together
|
||||||
|
|
||||||
If you need variable length args, you need izip for now.
|
If you need variable length args, you need izip for now.
|
||||||
|
|
Loading…
Add table
Reference in a new issue