Test name | Executions per second |
---|---|
Test1 | 20590990.0 Ops/sec |
Test2 | 5608173.0 Ops/sec |
<!--your preparation HTML code goes here-->
/*your preparation JavaScript code goes here
To execute async code during the script preparation, wrap it as function globalMeasureThatScriptPrepareFunction, example:*/
async function globalMeasureThatScriptPrepareFunction() {
// This function is optional, feel free to remove it.
// await someThing();
}
/*
findOutlier([1,3,5,7,9,11,13,15,2]);
findOutlier2([1,3,5,7,9,11,13,15,2]);
*/
function findOutlier(integers){
odd = [];
even = [];
outlier = -1;
for (let x = 0; x < integers.length; x++) {
let num = integers[x];
if(num % 2 === 0 || num === 0) {
odd.push(num);
} else {
even.push(num);
}
if(integers.length - 1 === x) {
outlier = Number((odd.length === 1) ? odd : even);
}
}
return outlier;
}
function findOutlier2(int){
var even = int.filter(a=>a%2==0);
var odd = int.filter(a=>a%2!==0);
return even.length==1? even[0] : odd[0];
}
findOutlier2([2, 4, 0, 100, 4, 11, 2602, 36])
findOutlier([2, 4, 0, 100, 4, 11, 2602, 36])