1- /* Sum the numbers in an array
2-
3- In this kata, you will need to implement a function that sums the numerical elements of an array
4-
5- E.g. sum([10, 20, 30]), target output: 60
6- E.g. sum(['hey', 10, 'hi', 60, 10]) throws Error("sum requires an array of numbers") (sum can't add non-numerical elements, so it shouldn't guess)
7- */
8-
91const sum = require ( "./sum.js" ) ;
102
11- // Acceptance Criteria:
12-
13- // Given an empty array
14- // When passed to the sum function
15- // Then it should return 0
163test ( "given an empty array, returns 0" , ( ) => {
174 expect ( sum ( [ ] ) ) . toBe ( 0 ) ;
185} ) ;
@@ -38,23 +25,3 @@ test("throws when not given an array", () => {
3825 new Error ( "sum requires an array of numbers" )
3926 ) ;
4027} ) ;
41-
42- // Given an array with just one number
43- // When passed to the sum function
44- // Then it should return that number
45-
46- // Given an array containing negative numbers
47- // When passed to the sum function
48- // Then it should still return the correct total sum
49-
50- // Given an array with decimal/float numbers
51- // When passed to the sum function
52- // Then it should return the correct total sum
53-
54- // Given an array containing a value that isn't a number
55- // When passed to the sum function
56- // Then it should throw Error("sum requires an array of numbers")
57-
58- // Given something that isn't an array at all, such as "hey", 42 or no argument
59- // When passed to the sum function
60- // Then it should throw Error("sum requires an array of numbers")
0 commit comments