Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

return function from function split()

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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"));
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading