juan field
asked on
how can i get the sole odd and th sole even
// I used the this website to de - obfuscate. http://www.rot13.com/
/*
Problem description (see instructions for how to de-obfuscate).
Tvira n fgevat bs rira naq bqq ahzoref, svaq juvpu vf gur fbyr rira ahzore be gur fbyr bqq ahzore.
Gur erghea inyhr fubhyq or 1-vaqrkrq, abg 0-vaqrkrq.
Rknzcyrf :
qrgrpgBhgyvreInyhr("2 4 7 8 10"); // => 3 - Guveq ahzore vf bqq, juvyr gur erfg bs gur ahzoref ner rira
qrgrpgBhgyvreInyhr("1 10 1 1"); //=> 2 - Frpbaq ahzore vf rira, juvyr gur erfg bs gur ahzoref ner bqq
*/
///////// de- obfuscated /////////
// Given a string of even and odd numbers, find which is the sole even number or the sole odd number.
// The return value should be 1-indexed, not 0-indexed.
// Examples :
// detectOutlierValue("2 4 7 8 10"); // => 3 - Third number is odd, while the rest of the numbers are even
// detectOutlierValue("1 10 1 1"); //=> 2 - Second number is even, while the rest of the numbers are odd
function detectOutlierValue(str){
var res = "";
for(var i = 0; i < str.length; i++)
{
if(str.indexOf(i) % 2 !== 0)
res += str.indexOf(i);
}
return res;
}
detectOutlierValue("2 4 7 8 10");
//detectOutlierValue("1 10 1 1");
/*
Problem description (see instructions for how to de-obfuscate).
Tvira n fgevat bs rira naq bqq ahzoref, svaq juvpu vf gur fbyr rira ahzore be gur fbyr bqq ahzore.
Gur erghea inyhr fubhyq or 1-vaqrkrq, abg 0-vaqrkrq.
Rknzcyrf :
qrgrpgBhgyvreInyhr("2 4 7 8 10"); // => 3 - Guveq ahzore vf bqq, juvyr gur erfg bs gur ahzoref ner rira
qrgrpgBhgyvreInyhr("1 10 1 1"); //=> 2 - Frpbaq ahzore vf rira, juvyr gur erfg bs gur ahzoref ner bqq
*/
///////// de- obfuscated /////////
// Given a string of even and odd numbers, find which is the sole even number or the sole odd number.
// The return value should be 1-indexed, not 0-indexed.
// Examples :
// detectOutlierValue("2 4 7 8 10"); // => 3 - Third number is odd, while the rest of the numbers are even
// detectOutlierValue("1 10 1 1"); //=> 2 - Second number is even, while the rest of the numbers are odd
function detectOutlierValue(str){
var res = "";
for(var i = 0; i < str.length; i++)
{
if(str.indexOf(i) % 2 !== 0)
res += str.indexOf(i);
}
return res;
}
detectOutlierValue("2 4 7 8 10");
//detectOutlierValue("1 10 1 1");
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
HTML
Open in new window
Javascript
Open in new window
As you can see the function addEventListener creates two arrays. One with the odd numbers and the other with the even.So you can manipulate these arrays as you want.