svephoto

Aggregate Elements [JavaScript]

Aug 1st, 2021 (edited)
120
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let aggregateElements = (array) => {
  2.     let numbersArray = array.map(Number);
  3.     let sum = numbersArray.reduce((a, b) => a + b);
  4.  
  5.     let inverseValuesSum = 0;
  6.  
  7.     for (let i = 0; i < numbersArray.length; i++) {
  8.         inverseValuesSum += 1 / numbersArray[i];
  9.     }
  10.  
  11.     let stringConcat = numbersArray.join('');
  12.  
  13.     console.log(sum);
  14.     console.log(inverseValuesSum);
  15.     console.log(stringConcat);
  16. }
  17.  
RAW Paste Data