Skip to content

Instantly share code, notes, and snippets.

@gor181
Last active July 19, 2017 20:36
Show Gist options
  • Save gor181/60dd8f70eb6ef8b469fff1b5f91af8e1 to your computer and use it in GitHub Desktop.
Save gor181/60dd8f70eb6ef8b469fff1b5f91af8e1 to your computer and use it in GitHub Desktop.
simple reduce and map (from top of my head)
const reduce = (array, callback, initialValue) => {
let result;
for(let i = 0; i < array.length; i++) {
result = callback(result || initialValue, array[i], i);
}
return result;
};
const map = (array, callback) => {
return reduce(array, (res, item, index) => {
res.push(callback(item, index));
return res;
}, []);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment