Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. const __flattenReducer = (result,value,valueIndex,arr)=>{
  2. if(value instanceof Array){
  3. return value.reduce(__flattenReducer,result);
  4. }else{
  5. result.push(value);
  6. return result;
  7. }
  8. };
  9.  
  10. const flatten = function(arr){
  11. if(arr instanceof Array){
  12. return Array.prototype.reduce.apply(arr,[__flattenReducer,[]]);
  13. }else{
  14. throw new TypeError('Expected an array');
  15. }
  16. }
  17. module.exports = flatten;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement