Skip to content
Advertisement

A very big sum – Hacker Rank

I am trying to solve “A very big sum” challenge on Hacker Rank: https://www.hackerrank.com/challenges/a-very-big-sum/problem

In there I have to sum all the numbers in the array given so I came up with two solutions:

First solution

JavaScript

Second Solution

JavaScript

But none of them work and I don´t know why, I am thiniking maybe I am not writing it as Hacker Rank wants me to but I am not sure

Advertisement

Answer

sum += i; should be sum += ar[i];

Also return sum

JavaScript

Also reducer function should be like

JavaScript
User contributions licensed under: CC BY-SA
11 People found this is helpful
Advertisement