알고리즘 43 - Sum Arrays

jabae·2021년 10월 28일
0

알고리즘

목록 보기
43/97

Q.

Write a function that takes an array of numbers and returns the sum of the numbers. The numbers can be negative or non-integer. If the array does not contain any numbers then you should return 0.

Examples

Input: [1, 5.2, 4, 0, -1]
Output: 9.2

Input: []
Output: 0

Input: [-2.398]
Output: -2.398

A)

function sum (numbers) {
    return numbers.reduce((sum, cur) => sum + cur, 0)
};
profile
it's me!:)

0개의 댓글