I need to implement The split() function which takes a separator as an argument, returns a function that accepts string data that is split by the separator character into an ordered set of substrings, and returns an array of those substrings. And I don’t understand how to correctly write the second function that accepts string data that is split by the separator character into an ordered set of substrings, and returns an array of those substrings. How can I do it?
const split = (separator) => {
};
>Solution :
This is kinda like currying; here we’re returning another function, that takes a string, and returns the string split by the separator.
const split = (separator) => { // creates closure where we can access 'separator'
return (str) => str.split(separator); // use 'separator' here
};
console.log(split(".")("a.b.c"));