Ad

Rewrite solution with reduce()

Code
Diff
  • const addArr = (arr) => {
    
      if(arr.length === 0) {return null }
      return arr.reduce((prev,curr) => prev + curr, 0)
    
    };
    
    • const addArr = (arr) => {
    • let sum = 0;
    • for (let i = 0; i < arr.length; i++) {
    • sum += arr[i];
    • }
    • return sum || null;
    • if(arr.length === 0) {return null }
    • return arr.reduce((prev,curr) => prev + curr, 0)
    • };