perf(upperCase): Improve performance of upperCase by using for loops

This commit is contained in:
raon0211 2024-09-13 15:36:04 +09:00
parent 7f2e19dc31
commit 529cbf9f55
2 changed files with 13 additions and 4 deletions

View File

@ -95,4 +95,3 @@ export { ceil } from './math/ceil.ts';
export { floor } from './math/floor.ts';
export { round } from './math/round.ts';
export { parseInt } from './math/parseInt.ts';

View File

@ -14,7 +14,17 @@ import { getWords } from './_internal/getWords.ts';
* const convertedStr3 = upperCase('hyphen-text') // returns 'HYPHEN TEXT'
* const convertedStr4 = upperCase('HTTPRequest') // returns 'HTTP REQUEST'
*/
export const upperCase = (str: string): string => {
export function upperCase(str: string): string {
const words = getWords(str);
return words.map(word => word.toUpperCase()).join(' ');
};
let result = '';
for (let i = 0; i < words.length; i++) {
result += words[i].toUpperCase();
if (i < words.length - 1) {
result += ' ';
}
}
return result;
}