I’m looking for the fastest way to lowercase all letters that aren’t a part of AND in a phrase. I want to leave AND in its original case, whether it was and or AND should not change.
For example, barack AND obama should test equal to Barack AND Obama but not barack and obama. (notice the case difference in and)
Here is one approach, but I wonder if there is a shorter way or rather a way that avoids iterators:
var str = 'Barack AND Obama'; // should be barack AND obama after
str = str.split(/\s+/g).map(function (s) {
return s.toLowerCase() != 'and' ? s.toLowerCase() : s;
}).join(' ');
You can lowercase every word that’s not exactly AND using a negative lookahead: