Skip to content

Instantly share code, notes, and snippets.

@dance2die
Created April 14, 2018 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dance2die/f7d63fb3456beff63103efa94b1671b8 to your computer and use it in GitHub Desktop.
Save dance2die/f7d63fb3456beff63103efa94b1671b8 to your computer and use it in GitHub Desktop.
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