const sum = arr => arr.flat().map(x => parseFloat(x) || 0).reduce((a, b) => a + b, 0); alert(sum([1, 2, '3x'])); alert(sum([1, 2, 'x3'])); alert(sum([1, [1, 2], 2]));