Skip to content
RSS feed tkhwang on GitHub tkhwang on Twitter

For statement for fixed and relatively small number in javascript

✨ Nested for statement : [object Object] time complexity

for (let i = 0; i < N;; i += 1) {
    for (let j = i + 1; j < N; j += 1) {
        // do something
    }
}

✨ For statement for fixed and relatively small number

  • It doesn't depend on the input data size.
  • If its size is relatively small and its value is fixed, the overall time complexity is much faster than that.

πŸ€ for alphabets (26) :

for (let i = 0; i < 26; i += 1) {
  for (let j = i + 1; j < 26; j += 1) {
    ///
  }
}

πŸ€ for data ranges (50) :

for (let i = -50; i < 0; i += 1) {
  //
}

πŸ—’οΈ Typical problems