DEV Community

Cover image for HackerRank — Problem Solving — JavaScript — A Very Big Sum
Abu Saleh Faysal
Abu Saleh Faysal

Posted on

HackerRank — Problem Solving — JavaScript — A Very Big Sum

Image description

The task is to find and print the sum of the elements in an array, keeping in mind that some of those integers may be quite large.

Solution:

Image description

Explanation:

Step 01: Take one variable named "sum" and store an initial value as zero(0).

Step 02: Iterate a for loop through the given array.

Step 03: While iterating the array we are going to add the array element with the variable named "sum".

Step 04: Return the overall summation at the very end after iterating the whole array.

Top comments (2)

Collapse
 
frankwisniewski profile image
Frank Wisniewski

In 2023 we will probably put it this way

  const aVeryBigSum = ( ar ) => 
    ar.reduce( ( a, c ) => a + c )
Enter fullscreen mode Exit fullscreen mode
Collapse
 
abusalehfaysal profile image
Abu Saleh Faysal

Thanks for your valuable suggestion. Will try to use it next time.