follow along with tests
This commit is contained in:
parent
f58ef53347
commit
9bd54f4719
4 changed files with 57 additions and 1 deletions
16
parts/4/blogApp/src/utils.js
Normal file
16
parts/4/blogApp/src/utils.js
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
const reverse = (string) => {
|
||||
return string.split("").reverse().join("");
|
||||
};
|
||||
|
||||
const average = (array) => {
|
||||
const reducer = (sum, item) => {
|
||||
return sum + item;
|
||||
};
|
||||
|
||||
return array.length === 0 ? 0 : array.reduce(reducer, 0) / array.length;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
reverse,
|
||||
average,
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue