Array.fromadvancedfunction sum() {
return Array.from(arguments).reduce((a, b) => a + b, 0)
}
sum(1, 2, 3) // β 6Use Array.from(arguments) to convert the arguments object into a real array.
The legacy arguments object inside a function is array-like (has length and integer keys) but is not a real array. Array.from(arguments) converts it into one so you can use array methods.
With modern TypeScript you'd use rest parameters (...args), but knowing how to convert arguments is useful when working with older code.
Challenge: Implement sumAll that accepts any number of numbers and returns their sum. Use Array.from inside the implementation.
sumAll(1, 2, 3) // β 6
sumAll(10, 20) // β 30