JSFiddle - React, Tailwind, and code Playground

by denniswaltermartinez

JavaScript

function sum(arr) {
  return arr.reduce((a, b) => {
  	
    if (Array.isArray(b)) {
    	b = sum(b)
    }
    
    return a + b
  }, 0)
}

console.log(sum([1, 2, 3, [4, 5, 6, [7, 8, 9]]]))