Сообщение от dc65k
|
getNumChars(3)
|
str => getNumChars(str, 3)
Оно?
const igor = {
name: 'igor',
}
const getName = person => person.name;
const upperCase = str => str.toUpperCase();
const get3Chars = str => str.substring(0, 3);
const getNumChars = (str, n) => {
// console.log('str', str)
// console.log('n', n)
return str.substring(0, n)
}
const reverse = str => str.split('').reverse().join('');
// Solution
const pipe = (...fns) => init => fns.reduce((value, f) => f(value), init);
const fn = pipe(getName, upperCase, get3Chars, reverse);
console.log(fn(igor)); // OGI
console.log(pipe(getName, upperCase, get3Chars, reverse)(igor)); // OGI
console.log(pipe(getName, upperCase, str => getNumChars(str, 3), reverse)(igor)); // Error