combining two filter functions

Viewed 250

I'd like to combine two filter functions I'm using to select a few elements in a table. my code looks like this:

a = $('table td').filter(function(index) {
    return index >= number1
}); 
                        
b = $('table td').filter(function(index) {
    return index < number2
});
                        
merge = $.merge(a, b);

The elements from a have to be first and in one row. so if a returns 3 elements they have to be in one row, follow by the elements from b. how can I achieve that? can I combine the filter functions from above?

1 Answers

you better use .slice method instead of filters, in a way like:

list = $('table td')
merge = [...list.slice(number1), ... list.slice(0, number2)]

or if you really want to use filter then:

list = $('table td')
merge = list.filter((item, i) => (i >= number1 || i < number2)  )
Related