This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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