Quick actions

cmd+k|ctrl+k

Navigation

Languages

Nemo

Snippet info

Language

JavaScript

Visibility

public

Author

my.samnang

Created

2025-02-06T21:18:42.033735Z

Updated

2025-02-06T21:23:38.223746Z

const nemo = ['nemo'];
const everyone = [
  'dory',
  'bruce',
  'marlin',
  'nemo',
  'gill',
  'bloat',
  'nigel',
  'squirt',
  'darla',
  'hank',
];
const large = new Array(200).fill('nemo');

function findNemo(array) {
  let t0 = performance.now();
  for (let i = 0; i < array.length; i++) {
      console.log('running');
    if (array[i] === 'nemo') {
      console.log('Found Nemo!');
      break;
    }
  }
  let t1 = performance.now();
  console.log('Call to find Nemo took ' + (t1 - t0) + ' milliseconds');
}

findNemo(everyone); // O(n) --> Linear Time - Operation (number of inputs) in our example n is 10
INFO