Advertisement
elena1234

JavaScript - map, reduce, join

Aug 2nd, 2021 (edited)
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let aggregateElements = (array) => {
  2.     let numbersArray = array.map(Number); // map
  3.     let sum = numbersArray.reduce((a, b) => a + b);
  4.  
  5.     let inverseValuesSum = numbersArray.reduce((a, b) => a + 1 / b, 0); // reduce
  6.     let stringConcat = numbersArray.join(''); // join
  7.     console.log(sum);
  8.     console.log(inverseValuesSum);
  9.     console.log(stringConcat);
  10. }
  11.  
  12.  
  13. aggregateElements([2, 4, 8, 16]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement