Write a function called add which takes in an array and returns the result of adding up every item in the array. add([1,2,3]) -> 6
// Imperative
function add (arr) {
let result = 0
for (let i = 0; i < arr.length; i++){
result += arr[i]
}
return result
}
// Declarative
function add (arr) {
return arr.reduce((prev, current) => prev + current, 0)
}