Skip to content
This repository was archived by the owner on Dec 27, 2023. It is now read-only.

Commit 69da7c9

Browse files
committed
composition is awesome
1 parent 30959e0 commit 69da7c9

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

composition/index.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
function composition (...callbacks) {
2+
return function (value) {
3+
return callbacks.reduce((accumulator, callback) => {
4+
return callback(accumulator)
5+
}, value)
6+
}
7+
}
8+
9+
function lowercaseText (text) {
10+
return text.toLowerCase()
11+
}
12+
13+
function addEmojis (text) {
14+
return `${text} 🦆🐖🐄`
15+
}
16+
17+
function separateText (text) {
18+
return text.split('').join(' ')
19+
}
20+
21+
const makeNiceText = composition(lowercaseText, addEmojis, separateText)
22+
23+
console.log( makeNiceText('Hello there') )
24+
console.log( makeNiceText('Composition is AWESOME') )

0 commit comments

Comments
 (0)