Skip to content
This repository has been archived by the owner on May 19, 2021. It is now read-only.

Commit

Permalink
[feat] add math module with sum function
Browse files Browse the repository at this point in the history
  • Loading branch information
cedoor committed Dec 8, 2019
1 parent 586c104 commit 31e6200
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
export { download } from './general/download'
// Http
export { get } from './http/get'
// Math
export { sum } from './math/operations.js'
// Strings
export { parseURL } from './strings/parseURL'
export { capitalize, capitalizeList } from './strings/capitalize'
12 changes: 12 additions & 0 deletions src/math/operations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Get numbers and return their sum.
* @param numbers
* @returns {number}
*/
export function sum (...numbers) {
if (numbers.some(number => typeof number !== 'number')) {
throw TypeError('Parameters must be numbers.')
}

return numbers.reduce((a, b) => a + b, 0)
}
10 changes: 10 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
const tape = require('tape')
const utils = require('../dist/utils')

/** Math module tests **/

tape('Operation functions', function (test) {
test.equal(utils.sum(1, 1, 2), 4)

test.throws(() => utils.sum(1, 2, 'hello'))

test.end()
})

/** String module tests **/

tape('Capitalize functions', function (test) {
Expand Down

0 comments on commit 31e6200

Please sign in to comment.