perf(sum): Improve performance of sum (#167)

This commit is contained in:
Doga Genc 2024-07-12 03:21:01 +03:00 committed by GitHub
parent 6aca4b2f4a
commit 34be6d7611
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -14,8 +14,8 @@
export function sum(nums: readonly number[]): number {
let result = 0;
for (const num of nums) {
result += num;
for (let i = 0; i < nums.length; i++) {
result += nums[i];
}
return result;