AFFILIATE LINKS
Great resource I use to learn algorithms.
40% off Tech Interview Pro: http://techinterviewpro.com/terriblewhiteboard
20% off CoderPro: http://coderpro.com/terriblewhiteboard
Here is the full implementation.
Method 1
let toLowerCase = function(str) {
return str.toLowerCase();
};
Method 2
let toLowerCase = function(str) {
let result = '';
for (let char of str) {
result += char.toLowerCase();
}
return result;
};
Method 3
let toLowerCase = function(str) {
let res = '';
str.split('').forEach( (s, index) => {
let code = str.charCodeAt(index);
if (code >= 65 && code < 91 ) {
code += 32;
}
res += String.fromCharCode(code);
});
return res;
};