From f83dcce3467f31823b471e13c7a93b0125efb814 Mon Sep 17 00:00:00 2001 From: RiverTwilight Date: Mon, 2 Jan 2023 19:13:36 +0800 Subject: [PATCH] fix: doesnt return anything --- .../chapter_computational_complexity/time_complexity.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/codes/javascript/chapter_computational_complexity/time_complexity.js b/codes/javascript/chapter_computational_complexity/time_complexity.js index 803b15c8..9fafb965 100644 --- a/codes/javascript/chapter_computational_complexity/time_complexity.js +++ b/codes/javascript/chapter_computational_complexity/time_complexity.js @@ -24,9 +24,10 @@ class time_complexity { arrayTraversal(nums) { var count = 0; // 循环次数与数组长度成正比 - nums.forEach(() => { + for (var i = 0; i < nums.length; i++) { count++; - }); + } + return count; } /* 平方阶 */