-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
beeraman
committed
May 19, 2018
1 parent
5d8a725
commit 3a1bb7d
Showing
8 changed files
with
312 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
function isEven(input) { | ||
return input%2 === 0; | ||
} | ||
function isOdd(input) { | ||
return input%2 === 1; | ||
} | ||
function isNegative(input) { | ||
return input < 0; | ||
} | ||
function isPositive(input) { | ||
return input >= 0; | ||
} | ||
function sumOfNumbers(n1, n2) { | ||
var result = 0; | ||
if(arguments.length > 1) { | ||
for(var i = 0 ; i < arguments.length ; i++) { | ||
result += arguments[i]; | ||
} | ||
} else { | ||
if(Array.isArray(n1)) { | ||
n1.forEach(function(item, idx) { | ||
result += item; | ||
}); | ||
} else if(Number.isInteger(n1)) { | ||
for(var i = 0 ; i <= n1 ; i++) { | ||
result += i; | ||
} | ||
// } else { | ||
// throw 'sumOfNumbers input must be either anarray of numbers or an integer' | ||
} | ||
} | ||
return result; | ||
} | ||
function sumOfNumbersBetween(a, b) { | ||
if(a && b) { | ||
var result = 0; | ||
for(var i = a++ ; i < b ; i++) { | ||
result += i; | ||
} | ||
return result; | ||
} else { | ||
return a || b || 0; | ||
} | ||
} | ||
function sumOfNumbersFrom(a, b) { | ||
if(a && b) { | ||
var result = 0; | ||
for(var i = a ; i <= b ; i++) { | ||
result += i; | ||
} | ||
return result; | ||
} else { | ||
return a || b || 0; | ||
} | ||
} | ||
function sumOfSquares(inputArr) { | ||
var args = arguments; | ||
var result = 0; | ||
//if an array | ||
if(args.length === 1) { | ||
inputArr.forEach(getSquares); | ||
} else { | ||
for(var i=0; i<args.length; i++){ | ||
getSquares(args[i]); | ||
} | ||
} | ||
function getSquares(item) { | ||
result += Math.pow(item, 2); | ||
} | ||
return result; | ||
} | ||
function sumOfCubes(inputArr) { | ||
var args = arguments; | ||
var result = 0; | ||
//if an array | ||
if(args.length === 1) { | ||
inputArr.forEach(getCubes); | ||
} else { | ||
for(var i=0; i<args.length; i++){ | ||
getCubes(args[i]); | ||
} | ||
} | ||
function getCubes(item) { | ||
result += Math.pow(item, 3); | ||
} | ||
return result; | ||
} | ||
|
||
function calcAverage(inputArr) { | ||
if(Array.isArray(inputArr)) { | ||
var result = sumOfNumbers(inputArr); | ||
return result/inputArr.length; | ||
// } else { | ||
// throw 'calcAverage input must be an array of numbers'; | ||
} | ||
} | ||
|
||
module.exports = { | ||
isEven: isEven, | ||
isOdd: isOdd, | ||
isPositive: isPositive, | ||
isNegative: isNegative, | ||
sumOfNumbers: sumOfNumbers, | ||
sumOfNumbersBetween: sumOfNumbersBetween, | ||
sumOfNumbersFrom: sumOfNumbersFrom, | ||
sumOfSquares: sumOfSquares, | ||
sumOfCubes: sumOfCubes, | ||
calcAverage: calcAverage | ||
}; |
Oops, something went wrong.