Help with Codewars partitionOn KATA

Asked

Viewed 182 times

1

The exercise I’m doing did not give error in the tests, but when I give Ubmit, it gives error, and I don’t know where I’m going wrong, someone could help me?

http://www.codewars.com/kata/525a037c82bf42b9f800029b/train/javascript

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 checksum method (even or odd) that returns a boolean value (true, false) and a numerical 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
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.