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
let map = (func, arr) => | |
arr.length == 0 ? | |
[] : ((x, y) => [...y, x])(func(arr.pop()), map(func, arr)) | |
// if you want to pull an one-liner: | |
// let map = (func, arr) => arr.length == 0 ? [] : ((x, y) => [...y, x])(func(arr.pop()), map(func, arr)) | |
let reduce = (func, initial_value, arr) => | |
arr.length == 0 ? | |
initial_value : ((x, y) => func(y, x))(arr.pop(), reduce(func, initial_value, arr)) |