mirror of
https://github.com/toss/es-toolkit.git
synced 2024-11-28 12:05:41 +03:00
perf(upperCase): Improve performance of upperCase by using for loops
This commit is contained in:
parent
7f2e19dc31
commit
529cbf9f55
@ -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';
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user