I have a string that I want to do a process to it:
1) split it by '.' and make an array
2) make each word and character to lower case
3) trim the array elements
I know that we can do this by coding each step separately but I want to do this in one line.
But it confused me why I can't do this using map(s => s.toLowerCase() && s.trim()) only the last method in the map works?
Any suggestions would be greatly appreciated.
let trapSt = ' I Was Sent = I Sent. To Earth = To Moon '
trapSt = trapSt.split(".")
only_LowerCase_Works_Here = trapSt.map(s => s.trim() && s.toLowerCase()); // ??? why only s.toLowerCase() works here???!!!!
only_Trim_Works_Here = trapSt.map(s => s.toLowerCase() && s.trim()); // ??? why only s.trim() works here???!!!!
console.log(only_LowerCase_Works_Here);
console.log(only_Trim_Works_Here);
s.toLowerCase().trim()or you could simply usetoLowerCaseon the original string before doing thesplit.