-
-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy path5-curry.js
More file actions
25 lines (21 loc) · 633 Bytes
/
5-curry.js
File metadata and controls
25 lines (21 loc) · 633 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
'use strict';
// Check 4 digit pin.
const EXPECTED_PIN = '4967';
const checkPin = (...code) => code.join('') === EXPECTED_PIN;
// Define function curry that accepts the length of the function
// (amount of function arguments) and the function.
// prettier-ignore
const curry =
(length, fn) =>
(...args) => {
if (length > args.length) {
const f = fn.bind(null, ...args);
return curry(length - 1, f);
} else {
return fn(...args);
}
};
// Allows to enter pin code by one character,
// Usage: press('3')('4')('5')('6')
const press = curry(4, checkPin);
module.exports = { press };