Add Number List

by MegaScience

JavaScript

const addNumbers = numberList => numberList.split(/[^\d]+/).reduce((s, i) => s + parseInt(i, 10), 0)
const nL = `250
2900
540
65
1745

40
40
40
40
40
40

40
40
40
40
40
40

315
45
565
1720
1715
305

1720
10
2085
30
5
5

50
2045
50
10
193
2930

130
2075
5
710
50
1315

2070
1770
5
2175
2125
45

1720
1780
320
1780
360
5
1720

285
1805
5
50
1800
1800

745
10
452
1705
5
5

380
50
2090`
document.body.textContent = addNumbers(nL)


/*function doStuff() {
  const numberList = `250
2900
540
65
1745

40
40
40
40
40
40

40
40
40
40
40
40

315
45
565
1720
1715
305

1720
10
2085
30
5
5

50
2045
50
10
193
2930

130
2075
5
710
50
1315

2070
1770
5
2175
2125
45

1720
1780
320
1780
360
5
1720

285
1805
5
50
1800
1800

745
10
452
1705
5
5

380
50
2090`
  const numberArray = numberList.split(/[^\d]+/)
  console.log(numberArray)
  const reducer = (s, i) => s + parseInt(i, 10)
  const reducerTest = (s, i) => {
		if(i === 0) console.log('Well lookie fuckin\' here.')
    const num = parseInt(i, 10)
    const io = s
    const res = s + num
    console.log(s, num, io, res)
    return res
  }
  let initialValue = 0
  return numberArray.reduce(reducer, 0)
}*/