diff --git a/getPositiveSum.test.js b/getPositiveSum.test.js new file mode 100644 index 00000000..e7269c5b --- /dev/null +++ b/getPositiveSum.test.js @@ -0,0 +1,4 @@ +const getPositiveSum = require("./index"); +test("Returns some of posetives", () => { + expect(getPositiveSum()).toBe(18); +}); \ No newline at end of file diff --git a/index.js b/index.js index ff28a6f9..f6db8364 100644 --- a/index.js +++ b/index.js @@ -1,22 +1,41 @@ -class NumberArray { - constructor(numbers) { - this.numbers = numbers; - } +// class NumberArray { +// constructor(numbers) { +// this.numbers = numbers; +// } + +// getPositiveSum() { +// let sum = 0; +// for (let number of this.numbers) { +// if (number > 0) { +// sum += number; +// } +// } +// return sum; +// } +// } + +// const numbers = [2, -4, 6, -8, 10, -12]; +// const numberArray = new NumberArray(numbers); +// const positiveSum = numberArray.getPositiveSum(); + +// Input: [2, -4, 6, -8, 10, -12] +// Output: 18 - getPositiveSum() { - let sum = 0; - for (let number of this.numbers) { - if (number > 0) { - sum += number; - } +getPositiveSum = () => { + let sum = 0; + for (let number of numbers) { + if (number > 0) { + sum += number; } - return sum; } + return sum; } - +module.exports = getPositiveSum; const numbers = [2, -4, 6, -8, 10, -12]; -const numberArray = new NumberArray(numbers); -const positiveSum = numberArray.getPositiveSum(); +console.log(getPositiveSum(numbers)); -// Input: [2, -4, 6, -8, 10, -12] -// Output: 18 + +// //Functions do specific things, classes are specific things. +// Classes often have methods, which are functions that are associated with +// a particular class, and do things associated with the thing that the class is - +// but if all you want is to do something, a function is all you need.