//import require performance hooks library to use persormce
const { performance } = require('perf_hooks');
// declaring array called nemo and setting first index to string 'nemo'
const nemo = ['wsup', 'you ugly', 'ya momma', 'nemo'];
//create new large array
const large = new Array(1000000).fill('nemo');
// create function to look thru array and find vaue of nemo
function findNemo (array){
try{
//get time now
let t0 = performance.now();
console.log("time before is: " + t0);
let i=0, j = array.length;
//check if array is empty
if(j === 0){
return;
}
//loop thru array to find string nemo
for(; i < j; i++){
if(array[i] === 'nemo'){
console.log('Found Nemo!');
}
}
let t1 = performance.now();
console.log("time after is: " + t1);
console.log('time took to find nemo is: ' + (t1-t0));
} catch (err) {
console.err(err);
throw err;
}
}
//function call; pass in array to function
findNemo(large);