I have trouble with building composition function, using an array as an argument. Got this error
TypeError: arr.map is not a function
const testArray = ["CusTom", "Web", "aNd", "MoBile", "PlaTfoRms"];
const compose =
(...fncs) =>
(val) =>
fncs.reduceRight((acc, fnc) => fnc(acc), val);
const modifyArray = (ModifyCondition) => (data) => ModifyCondition(data);
let capitalizeAllFirst = modifyArray(
compose(
(arr) =>
arr.map(
(str) => str.charAt(0).toUpperCase() + str.slice(1).toLowerCase()
),
(arr) => arr.join("-")
)
);
let allToLower; // use compose + modifyArray here
console.log(capitalizeAllFirst(testArray));
I tried to use one argument in compose and it worked well
let capitalizeAllFirst = modifyArray(
compose(
(arr) =>
arr.map(
(str) => str.charAt(0).toUpperCase() + str.slice(1).toLowerCase()
)
)
);