Quick actions

cmd+k|ctrl+k

Navigation

Languages

Big O Calculation

Snippet info

Language

JavaScript

Visibility

public

Author

teri

Created

2020-06-21T10:59:11Z

Updated

2020-06-22T09:28:54Z

// What is the Big O of the below function? (Hint, you may want to go line by line)
function funChallenge(input) {
  let a = 10; // O(1)
  a = 50 + 3; // O(1)

  for (let i = 0; i < input.length; i++) { // O(n)
    anotherFunction(); // O(n)
    let stranger = true; 
    a++; // O(n)
  }
  return a; // O(1)
}

function anotherFunction(){
    console.log('howdy');
}
const result = funChallenge([0, 1, 2, 3, 4, 5]);
console.log(result, 'BIG O: 3 + 4n')
INFO