DEV Community

Cover image for Simple Array Sum –[HackerRank Coding Challenge]
Ghameerah McCullers
Ghameerah McCullers

Posted on

Simple Array Sum –[HackerRank Coding Challenge]

Warning, it is assumed that if you are reading this you understand JavaScript ES6 concepts.


Given an array of integers, find the sum of its elements.

For example, if the array [1,2,3], 1 + 2 + 3 = 6 , so return 6.

Function Description

Complete the simpleArraySum function in the editor below. It must return the sum of the array elements as an integer.

simpleArraySum has the following parameter(s):

ar: an array of integers


const simpleArraySum = arr => arr.reduce((acc,curr) => acc + curr, 0) 
Enter fullscreen mode Exit fullscreen mode

Read more on the reduce() JavaScript ES6 array method here =>

P.s. here's another really cool resource I like for learning more about JavaScript and reduce() =>

Happy Coding!

Discussion (0)