js-mentorship-razvan / javascript

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

Sum of Odd Cubed Numbers #492

Closed RazvanBugoi closed 4 years ago

RazvanBugoi commented 4 years ago

https://www.codewars.com/kata/580dda86c40fa6c45f00028a/train/javascript

RazvanBugoi commented 4 years ago
function cubeOdd(arr) {
  let odd = [];
  let cubed = arr.map((el) => Math.pow(el, 3));
  if (arr.filter((element) => typeof(element) == 'number').length == arr.length) {
    for (let i=0; i<cubed.length; i++) {
      if (cubed[i] % 2 != 0) odd.push(cubed[i]);
    }
    return odd.reduce((a,b) => a+b, 0);
  } else {
      return undefined;
    }
}