7 kyu

Sum of all arguments

5,143 of 12,290user578387

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 Trained16702
Total Skips1622
Total Code Submissions28738
Total Times Completed12290
JavaScript Completions5143
CoffeeScript Completions199
Ruby Completions1355
Python Completions5043
Clojure Completions747
PHP Completions480
C Completions187
Scala Completions40
Total Stars98
% of votes with a positive feedback rating89% of 1063
Total "Very Satisfied" Votes860
Total "Somewhat Satisfied" Votes173
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
  • Just4FunCoder Avatar
  • KayleighWasTaken Avatar
Ad