Implement String.prototype.toLowerCase()
Description
The toLowerCase
method returns the value of the string converted to lowercase
. toLowerCase does not affect the value of the string itself.
Conditions Let count chars inside function and ignore all bootstrap code:
String.prototype.toLowerCase = function(){
// code that count here
}
Other languages are welcome but JavaScript implemantation is target of this question. Let's just focus on ASCII charachters .
Example input and output:
"sOmeText".toLowerCase(); => "sometext"
Example implementation:
String.prototype.toLowerCase = function(){
return this.split('').map(function(c){
var cc = c.charCodeAt(0);
if (cc > 64 && cc < 91) {
return String.fromCharCode(cc + 32);
}
return c;
}).join('');
}
String.prototype.toLowerCase.apply(new Date());
on StackOverflow with a quick search; what is the input going to be? \$\endgroup\$ú
, obviously. That's whatString.prototype.toLowerCase()
does. \$\endgroup\$