more efficient Big O | O(n)

Run Settings
LanguageJavaScript
Language Version
Run Command
// array const nemo = ['nemo']; const everyone = ['dory', 'bruce', 'marlin', 'nemo', 'gill', 'bloat', 'nigel', 'squirt', 'darla', 'hank']; const large = new Array(1000).fill('nemo'); // function recieves array function findNemo(array) { //to measure time at the beginnig // let t0 = performance.now(); for (let i = 0; i < array.length; i++) { if (array[i] === 'nemo') { console.log('Found NEMO!!'); break; // making it more efficient } } // another timer at the loop end // let t1 = performance.now(); // console.log('Call to find Nemo took ' + (t1-t0) + 'milliseconds'); } //findNemo(nemo); //findNemo(everyone); findNemo(large); // O(n) -- Linear Time
Editor Settings
Theme
Key bindings
Full width
Lines