Basically the same, but with a dumber (pointlessly intricate) regex, and a reduce() integrating map() + join() into one iteration. I|m also lowercasing all letters in n1+ words in case they contain some uppercase characters inside:
const solve = (strArg) => {
return strArg
.match(/[^0-9|\W]\w+/g)
.reduce((a, w, i) => {
if (i === 0) {
return a + w.toLowerCase();
} else {
return a + (w[0].toUpperCase() + w.slice(1).toLowerCase());
}
}, '');
};
zunair jarral3 years ago
is there anybody advise on One Liner code
const solve = (strArg) => {
let a = strArg.replace(/[^a-z\s]/gi, " ").toLowerCase().trim().split(" ");
let b = a.slice(0,1);
let c = a.slice(1);
let d = c.map((pro) => {
let firstLetter = pro.slice(0,1);
let capitalized = firstLetter.toUpperCase();
return pro.replace(firstLetter, capitalized)
});
let e = d.filter(n => n);
return [...b, ...e].join("");
};
Comments
Tuong Vi Pham2 years ago
Bryan Guilas2 years ago
solutions Bedfordshire2 years ago
A one-liner, not great though...
const solve = (strArg) => strArg.split("").map((x, index) => strArg[index - 1] < 'A' || strArg[index - 1] > 'z' ? x.toUpperCase() : x.toLowerCase()).filter(x => x >= 'A' && x <= 'z' ).map((x, index) => index === 0 ? x.toLowerCase() : x).join("");
Ameliorated Tugrik2 years ago
a piece of cake! :D
const solve = str => str.match(/\b[a-zA-Z]+\b/g).map((i, n) => (n === 0 ? i[0].toLowerCase() : i[0].toUpperCase()) + i.slice(1)).join('')
Forges2 years ago
Coordinator proactive2 years ago
Basically the same, but with a dumber (pointlessly intricate) regex, and a
reduce()
integratingmap() + join()
into one iteration. I|m also lowercasing all letters inn1+
words in case they contain some uppercase characters inside:zunair jarral3 years ago
is there anybody advise on One Liner code
const solve = (strArg) => { let a = strArg.replace(/[^a-z\s]/gi, " ").toLowerCase().trim().split(" "); let b = a.slice(0,1); let c = a.slice(1); let d = c.map((pro) => { let firstLetter = pro.slice(0,1); let capitalized = firstLetter.toUpperCase(); return pro.replace(firstLetter, capitalized) }); let e = d.filter(n => n); return [...b, ...e].join(""); };
Abdelhamid Ismail3 years ago
Good job mate!
this regular expressions drive me nuts! :D
your soulution in better formating