Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.