17
loading...
This website collects cookies to deliver better user experience
["INNOVATION","DISTINGUISHES","BETWEEN","LEADER","AND","FOLLOWER"]
let str = 'Innovation distinguishes between a leader and a follower.!!'
let prepareString = function () {
let str1 = str.trim();
let str2 = str1.replace(/[?.,!]/g, '')
let str3 = str2.toUpperCase();
let arr = str3.split(" ");
for(let i = 0; i < arr.length; i++) {
if(arr[i] === 'A' || arr[i] === 'AN' || arr[i] === 'THE') {
arr.slice(i,1);
}
}
return arr;
}
str = "Innovation distinguishes between a leader and a follower.!!"
const str = 'Innovation distinguishes between a leader and a follower.!!'
const trimString = str => str.replace(/^\s*|\s*$/g, '');
const noPunction = str => str.replace(/[?.,!]/g, '');
const capitalizeStr = str => str.toUpperCase();
const splitStr = str => str.split(" ");
const noArticles = str => (str !== 'A' && str !== 'AN' && str !== 'THE');
const filterArticles = arr => arr.filter(noArticles);
console.log(filterArticles(splitStr(capitalizeStr(noPunction(trimString(str))))));
const compose = (...fns) => (x) => fns.reduce((value, currentFunction) => currentFunction(value), x);
const prepareString = compose(trimString, noPunction, capitalizeStr, splitStr, filterArticles);
console.log(prepareString(str));
["INNOVATION","DISTINGUISHES","BETWEEN","LEADER","AND","FOLLOWER"]
Functional programming is gaining a lot of popularity lately, and it is a good time to learn this programming paradigm. Though it has to remember that you won't be able to use the FP paradigm for all the scenarios.