Created
April 14, 2018 21:08
-
-
Save dance2die/f7d63fb3456beff63103efa94b1671b8 to your computer and use it in GitHub Desktop.
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