Skip to content
Permalink
c33b19b8ca
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
28 lines (22 sloc) 511 Bytes
function addOld(...values) {
let total = 0
console.log(values)
console.log(values[1])
for (let i=0; i<values.length; i++) {
total += values[i]
}
return total
}
function add2(...values) {
return values.reduce((acc, val) => acc + val)
}
const add = (...values) => values.reduce((acc, val) => acc + val)
console.log(add(1, 2, 3, 4))
function f5() {
let sum = 0
for (let i = 0, j = arguments.length; i < j; i++) {
sum += arguments[i]
}
return sum / arguments.length
}
console.log(f5(1, 2, 3))