js-mentorship-razvan / javascript

Javascript study notes
GNU General Public License v3.0
22 stars 2 forks source link

Find the odd int #534

Closed RazvanBugoi closed 4 years ago

RazvanBugoi commented 4 years ago

https://www.codewars.com/kata/54da5a58ea159efa38000836/train/javascript

RazvanBugoi commented 4 years ago
function findOdd(A) {
  let obj = {};
  A.forEach((el) => {
    if(el in obj) obj[el] +=1;
    else obj[el] = 1;
  });
  let value = Object.values(obj).filter((el) => el % 2 != 0);
  return parseInt(Object.keys(obj).filter((el) => obj[el] == value));
}