mirror of
https://github.com/krahets/hello-algo.git
synced 2026-11-24 12:42:23 +08:00
Retranslate the complete English edition from Simplified Chinese (#2010)
* Retranslate the complete English edition from Simplified Chinese * Polish three English explanations after reader-focused review
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
* Author: Hello Algo Team
|
||||
*/
|
||||
|
||||
/* Iterative summation */
|
||||
/* Sum using iteration */
|
||||
function sumIter(n) {
|
||||
let res = 0;
|
||||
for (let i = 1; i <= n; i++) {
|
||||
@@ -13,7 +13,7 @@ function sumIter(n) {
|
||||
return res;
|
||||
}
|
||||
|
||||
/* Recursive summation */
|
||||
/* Sum using recursion */
|
||||
function sumRecur(n) {
|
||||
if (n === 1) {
|
||||
return 1;
|
||||
@@ -21,7 +21,7 @@ function sumRecur(n) {
|
||||
return n + sumRecur(n - 1);
|
||||
}
|
||||
|
||||
/* Linear loop */
|
||||
/* Linear-time loop */
|
||||
function linearLoop(n) {
|
||||
let res = 0;
|
||||
for (let i = 0; i < n; i++) {
|
||||
@@ -30,7 +30,7 @@ function linearLoop(n) {
|
||||
return res;
|
||||
}
|
||||
|
||||
/* Quadratic loop */
|
||||
/* Quadratic-time loop */
|
||||
function quadraticLoop(n) {
|
||||
let res = 0;
|
||||
for (let i = 0; i < n; i++) {
|
||||
@@ -41,7 +41,7 @@ function quadraticLoop(n) {
|
||||
return res;
|
||||
}
|
||||
|
||||
/* Logarithmic loop */
|
||||
/* Logarithmic-time loop */
|
||||
function logarithmicLoop(n) {
|
||||
while (n > 1) {
|
||||
n = Math.floor(n / 2);
|
||||
@@ -59,5 +59,5 @@ if (
|
||||
logarithmicLoop(4) !== 1 ||
|
||||
logarithmicLoop(5) !== 1
|
||||
) {
|
||||
throw new Error('complexity exercise check failed');
|
||||
throw new Error('Complexity exercise check failed');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user