7 kyu

Sum The Array

1,191 of 1,194vasekhlav

Description:

Your job is to add a method 'sum' to all array objects, which sums all the numbers in it. You should return 0 if the array is empty.

For example:

var arr = [1,2,3,4];
arr.sum();  //returns 10

var arr = [10, 28, 14, 33];
arr.sum(); //returns 85
arr = [1,2,3,4]
arr.sum();  #returns 10

arr = [10, 28, 14, 33]
arr.sum(); #returns 85

Good luck!

Arrays
Fundamentals

More By Author:

Check out these other kata created by vasekhlav

Stats:

CreatedFeb 12, 2016
PublishedFeb 12, 2016
Warriors Trained2719
Total Skips77
Total Code Submissions3617
Total Times Completed1194
JavaScript Completions1191
CoffeeScript Completions18
Total Stars30
% of votes with a positive feedback rating93% of 231
Total "Very Satisfied" Votes200
Total "Somewhat Satisfied" Votes28
Total "Not Satisfied" Votes3
Ad
Contributors
  • vasekhlav Avatar
  • jhoffner Avatar
  • joh_pot Avatar
  • Unnamed Avatar
Ad