Skip to content

Instantly share code, notes, and snippets.

@yschen25
Last active March 21, 2022 23:22
Time complexity - O(n)
function listSum(n) {
let result = 0; // Assign 數值給變數,執行 1 次
for (let i = 0; i < n.length; i++) { // Loop array 執行 n 次
result += n[i];
}
return result; // Return 結果,執行 1 次
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment