Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5b396b2

Browse files
authored
Update README.md
1 parent 7db8ed4 commit 5b396b2

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

‎README.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,32 @@ console.log(twoByTwo); // [[a, b], [b, c], [c, d], [d, e], [e, f], [f, g]]
9999
Currying allows a function with multiple arguments to be translated into a sequence of functions. Curried functions can be tailored to match the signature of another function.
100100

101101
```javascript
102+
// Statement
103+
// function convertUnits(toUnit = 0, factor, offset) {
104+
// return function(input) {
105+
// return ((offset + input) * factor).toFixed(2).concat(toUnit)
106+
// }
107+
// }
108+
109+
// Can be written as an expression
102110
const convertUnits = (toUnit, factor, offset = 0) => input => ((offset + input) * factor).toFixed(2).concat(toUnit);
111+
103112
const milesToKm = convertUnits('km', 1.60936, 0);
104113
const poundsToKg = convertUnits('kg', 0.45460, 0);
105114
const farenheitToCelsius = convertUnits('degrees C', 0.5556, -32);
106-
milesToKm(10); // "16.09 km"
107-
poundsToKg(2.5); // "1.14 kg"
108-
farenheitToCelsius(98); // "36.67 degrees C"
115+
116+
console.log(milesToKm(10)); //"16.09 km"
117+
console.log(poundsToKg(2.5)); //"1.14 kg"
118+
console.log(farenheitToCelsius(98)); //"36.67 degrees C"
109119

110120
const weightsInPounds = [5, 15.4, 9.8, 110];
111-
// without currying
121+
122+
// Without currying
112123
// const weightsInKg = weightsInPounds.map(x => convertUnits('kg', 0.45460, 0)(x));
113-
// with currying
114-
const weightsInKg = weightsInPounds.map(poundsToKg); // 2.27kg, 7.00kg, 4.46kg, 50.01kg
124+
125+
// With currying
126+
const weightsInKg = weightsInPounds.map(poundsToKg);
127+
console.log(weightsInKg); // 2.27kg, 7.00kg, 4.46kg, 50.01kg
115128
```
116129

117130
<a href="https://codepen.io/Bunlong/pen/rrwmWR" target="_blank">Edit on Codepen</a>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /