Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const map = (array, func) => (
- array.map(func)
- );
- const flatMap = (array, func) => (
- array.reduce((result, element) => (
- result.concat(func(element))
- ), [])
- );
- const arr = ['two birds', 'three green peas'];
- const split = s => s.split(' ');
- map(arr, split)
- // [["two", "birds"], ["three", "green", "peas"]]
- flatMap(arr, split)
- // ["two", "birds", "three", "green", "peas"]
Add Comment
Please, Sign In to add comment