Help with Codewars KATA partitionOn

1

The exercise I'm doing did not give any errors in the tests, but when I submit, it makes a mistake, and I do not know where I'm going wrong, could anyone help me?

link

function partitionOn(pred, items) {
var sum_par = 0,
    sum_impar = 0;
var x = 0;    
for (var i in items) {
   if (pred(i) == true) {
       if (items[i] != undefined) {
          var par = items.splice(items[i]+1, 1);
          var impar = items.splice(par, 1);
          items.splice(1,0,par[0],impar[0]);
       }
   } else {
     sum_par += 1;
     items = sum_par;
   }
   x++;
}
return items;
}

Input Parameters:

1) Parameter is a method of checking (even or odd) that returns a Boolean value (true, false) and a numeric collection:

var items = [1, 2, 3, 4, 5, 6];
function isEven(n) {return n % 2 == 0}
var i = partitionOn(isEven, items);

2) The collection may also contain a removal with the method:

items.slice(0, i); //para retornar os ímpares
items.slice(i); //para retornar os pares
    
asked by anonymous 24.09.2015 / 03:01

0 answers