Created
April 14, 2018 21:09
-
-
Save dance2die/84d3bb00fafdb1ced427fc349c4135d7 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.take = function(count) { | |
return this.filter((_, i) => i < count); | |
}; | |
Array.prototype.takeWhile = function(predicate) { | |
return this.filter((_, i) => predicate(_, i)); | |
}; | |
function takeDemo(orders) { | |
const firstTwoOrders1 = orders.take(2); | |
printHeaderFooter( | |
"First Two Orders - Take", | |
() => printOrders(firstTwoOrders1, indentBy), | |
indentBy | |
); | |
const firstTwoOrders2 = orders.takeWhile((order, index) => index <= 1); | |
printHeaderFooter( | |
"First Two Orders - TakeWhile", | |
() => printOrders(firstTwoOrders2, indentBy), | |
indentBy | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment