0

I need to filter an array, so I've this code that works for a normal array

var arr = [138,124,128,126,140,113,102,128,136,110,134,132,130,132,132,104,116,135,120];

var limit = 112;

var lowarray = arr.filter(function(x) {
    return x <= limit;
});

var higharray = arr.filter(function(x) {
    return x > limit;
});

console.log(lowarray);
console.log('');
console.log(higharray);

The problem is that I've to apply it to a 2d array but I tried and no results!

for example I've this array

var arr [[1,5],[2,4],[3,6],[4,2],[5,2]];

I wanna split it with the same idea

var limit = 3;

so the lowarray would be

[[1,5],[2,4],[3,6]];

and the higharray would be

[[4,2],[5,2]];

Any Idea?

1
  • So what is the problem? Commented Oct 18, 2016 at 19:05

1 Answer 1

2

return x[0] > limit;

Since you seem to want to filter on the first element of the 2d array

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.