Skip to content

Commit 5bc9df9

Browse files
author
Ravindra Chhetri
committed
PATCH - removed split function
1 parent 6b7d7d1 commit 5bc9df9

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

implementations/toUpperCase.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@
1010
We're checking this condition to implement this function.
1111
*/
1212
String.prototype.toUpperCase = function myToUpperCase() {
13-
return this.split('').reduce((acc, character) => {
13+
let upperCaseString = '';
14+
for (let i = 0; i < this.length; i += 1) {
15+
const character = this[i];
1416
const charCode = character.charCodeAt();
1517
if (charCode >= 97 && charCode <= 122) {
16-
return acc + String.fromCharCode(charCode - 32);
18+
upperCaseString += String.fromCharCode(charCode - 32);
19+
} else {
20+
upperCaseString += character;
1721
}
18-
return acc + character;
19-
}, '');
22+
}
23+
return upperCaseString;
2024
};

0 commit comments

Comments
 (0)