기본 toLowerCase()를 덮어쓰고 기본 함수와 동일한 기능을 가져야 하는 JavaScript String 함수를 작성해야 합니다.
이 함수에 대한 코드를 작성해 봅시다 -
예시
const str = 'Some UpPerCAsE LeTTeRs!!!';
const toLowerCase = function(){
let str = '';
for(let i = 0; i < this.length; i++){
const ascii = this[i].charCodeAt();
if(ascii >= 65 && ascii <= 90){
str += String.fromCharCode(ascii + 32);
}else{
str += this[i];
};
};
return str;
};
String.prototype.toLowerCase = toLowerCase;
console.log(str.toLowerCase()); 출력
콘솔의 출력은 -
some uppercase letters!!!