Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Array.prototype.skip = function(count) {
return this.filter((_, i) => i >= count);
};
Array.prototype.skipWhile = function(predicate) {
return this.filter((_, i) => !predicate(_, i));
};
function skipDemo(orders) {
const lastTwoOrders1 = orders.skip(orders.length - 2);
printHeaderFooter(
"Last Two Orders - Skip",
() => printOrders(lastTwoOrders1, indentBy),
indentBy
);
const lastTwoOrders2 = orders.skipWhile(
(order, index) => index < orders.length - 2
);
printHeaderFooter(
"Last Two Orders - SkipWhile",
() => printOrders(lastTwoOrders2, indentBy),
indentBy
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.