Odd Even Count

Run Settings
LanguageJavaScript
Language Version
Run Command
// Input: ARRAY, int, // To find last even and odd ocuurence, count all occurence // [10,11,15,5,171,11,7,9,12] // NUM=11; // index even, index odd, count function findOccurrence(arr, num){ let count=0, odd=-1, even=-1; for(let i=arr.length-1; i>-1; i--){ if(arr[i]===num){ if(i%2==0){ even=i; break; } } } for(let i=arr.length-1; i>-1; i--){ if(arr[i]===num){ if(i%2!=0){ odd=i; break; } } } for(let i=arr.length-1; i>-1; i--){ if(arr[i]===num){ count++; } } console.log(`Even: ${even}`); console.log(`Odd: ${odd}`); console.log(`Count: ${count}`); } findOccurrence([10,11,15,5,11,11,7,9,12],11);
Editor Settings
Theme
Key bindings
Full width
Lines