7 kyu

Sum of all arguments

4,985 of 11,933user578387

Description:

Write a function that finds the sum of all its arguments.

eg:

sum(1, 2, 3) // => 6
sum(8, 2) // => 10
sum(1, 2, 3, 4, 5) // => 15
sum(1, 2, 3) // => 6
sum(8, 2) // => 10
sum(1, 2, 3, 4, 5) // => 15
sum_args(1, 2, 3) # => 6
sum_args(8, 2) # => 10
sum_args(1, 2, 3, 4, 5) # => 15
sum 1, 2, 3 # => 6
sum 8, 2 # => 10
sum 1, 2, 3, 4, 5 # => 15
sum 1, 2, 3 # => 6
sum 8, 2 # => 10
sum 1, 2, 3, 4, 5 # => 15
(sum 1 2 3) ; => 6
(sum 8 2) ; => 10
(sum 1 2 3 4 5) ; => 15
sum(3, 10, 20, 3); // --> 33
sum(2, 10, 15); // --> 25
sum(1, 10); // --> 10
sum(0); // --> 0

TIPS:

ruby/python : http://lmgtfy.com/?q=Ruby+splat+operator

JS/Coffeescript : http://lmgtfy.com/?q=Javascript+arguments+variable

C: https://www.geeksforgeeks.org/variadic-functions-in-c/

Fundamentals

Stats:

CreatedSep 7, 2014
PublishedSep 7, 2014
Warriors Trained16205
Total Skips1615
Total Code Submissions28125
Total Times Completed11933
JavaScript Completions4985
CoffeeScript Completions199
Ruby Completions1353
Python Completions4878
Clojure Completions745
PHP Completions461
C Completions164
Scala Completions39
Total Stars96
% of votes with a positive feedback rating89% of 1045
Total "Very Satisfied" Votes844
Total "Somewhat Satisfied" Votes171
Total "Not Satisfied" Votes30
Ad
Contributors
  • user578387 Avatar
  • jhoffner Avatar
  • xcthulhu Avatar
  • candrabeqx Avatar
  • donaldsebleung Avatar
  • Chrono79 Avatar
  • FArekkusu Avatar
  • hobovsky Avatar
  • trashy_incel Avatar
  • akar-0 Avatar
  • Kacarott Avatar
  • KayleighWasTaken Avatar
Ad