8 kyu

Sum Arrays

5,539 of 200,345richardhsu

Description:

Write a function that takes an array of numbers and returns the sum of the numbers. The numbers can be negative or non-integer. If the array does not contain any numbers then you should return 0.

Examples

Input: [1, 5.2, 4, 0, -1]
Output: 9.2

Input: []
Output: 0

Input: [-2.398]
Output: -2.398

Assumptions

  • You can assume that you are only given numbers.
  • You cannot assume the size of the array.
  • You can assume that you do get an array and if the array is empty, return 0.

What We're Testing

We're testing basic loops and math operations. This is for beginners who are just learning loops and math operations.
Advanced users may find this extremely easy and can easily write this in one line.

Arrays
Fundamentals

More By Author:

Check out these other kata created by richardhsu

Stats:

CreatedAug 2, 2014
PublishedAug 2, 2014
Warriors Trained274769
Total Skips15984
Total Code Submissions362569
Total Times Completed200345
Ruby Completions5539
JavaScript Completions73437
Haskell Completions1469
CoffeeScript Completions119
Clojure Completions887
Python Completions71929
C Completions5108
C# Completions10722
PHP Completions4811
R Completions787
Elixir Completions477
Dart Completions1726
Crystal Completions54
NASM Completions95
C++ Completions11077
Julia Completions157
Racket Completions86
Factor Completions43
Java Completions16915
Lua Completions393
Total Stars884
% of votes with a positive feedback rating91% of 11492
Total "Very Satisfied" Votes9663
Total "Somewhat Satisfied" Votes1551
Total "Not Satisfied" Votes278
Ad
Contributors
  • richardhsu Avatar
  • jhoffner Avatar
  • amclain Avatar
  • user578387 Avatar
  • freeman42x Avatar
  • Unnamed Avatar
  • joshwalters Avatar
  • Skrewtape Avatar
  • SithFire Avatar
  • myjinxin2015 Avatar
  • donaldsebleung Avatar
  • Chrono79 Avatar
  • JohanWiltink Avatar
  • lilsweetcaligula Avatar
  • Voile Avatar
  • mitron6 Avatar
  • Souzooka Avatar
  • mentalplex Avatar
  • monadius Avatar
  • user9644768 Avatar
  • hobovsky Avatar
  • user8436785 Avatar
  • ejini战神 Avatar
  • Kacarott Avatar
  • user3232161 Avatar
  • Just4FunCoder Avatar
  • fcr-- Avatar
  • PetitLu117 Avatar
Ad