-
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
1 parent
86fb4a9
commit bfdbd6d
Showing
7 changed files
with
114 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const add = require("./add.js"); | ||
const divide = require("./divide.js"); | ||
|
||
function mean(nums, options) { | ||
let count = 0; | ||
let total = "0"; | ||
for (let num of nums) { | ||
count++; | ||
total = add(total, num); | ||
} | ||
return divide(total, count.toString(), options); | ||
} | ||
|
||
module.exports = mean; | ||
module.exports.default = mean; |
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,9 @@ | ||
const compare = require("./compare"); | ||
|
||
function sort(nums, { direction = "ascending" } = { direction: "ascending" }) { | ||
const op = direction === "desc" || direction === "descending" ? "<" : ">"; | ||
return nums.sort((a, b) => (compare(a, b) === op ? 1 : -1)); | ||
} | ||
|
||
module.exports = sort; | ||
module.exports.default = sort; |
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,13 @@ | ||
const add = require("./add.js"); | ||
|
||
function sum(nums) { | ||
let total = "0"; | ||
// using iterator protocol | ||
for (let num of nums) { | ||
total = add(total, num); | ||
} | ||
return total; | ||
} | ||
|
||
module.exports = sum; | ||
module.exports.default = sum; |
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