What is the time complexity of an algorithm with the setTimeout function?

Viewed 54

Given the following sorting algorithm, what is the time complexity of the sort?

function sort(arr) {
  arr.forEach(i => {
    setTimeout(() => console.log(i), i)
  })
}

const n = [100, 1000000, 10000, 3600000, 3, 5, 0, 1, 9];
sort(n);

Output:

0
1
3
5
9
100
10000
3600000 // After 1 hour
0 Answers
Related