[Solved] Better way to write this javascript filter code? [closed]


Depends on why you’re doing what you’re doing with this code. If you’re just trying to golf it, one way to make it shorter is to remove the definitions of the lambdas and call them inline. Something like below

var numbers = [0,1,2,3,4,5,6,7,8,9];
var greaterthanvalues = ((numbers, value) => numbers.filter((number) => number > value ))(numbers, 5)
var reject = ((numbers) => numbers.filter((number) => number < greaterthanvalues[0]))(numbers, greaterthanvalues)

Updated answer to reflect your comments/edits

var numbers = [0,1,2,3,4,5,6,7,8,9];
var reject = (numbers, lambdaRet) => numbers.filter((number) => number < lambdaRet[0])
reject(numbers, ((numbers, value) => numbers.filter((number) => number > value ))(numbers, 5))

Explanation: Without rewriting the entire idea of what you’re doing, here’s one method of getting there. Reject is a function which takes two arrays as its parameters. When calling this function, I passed in the first array as numbers, and the second one as the result of the lambda function I defined and called inline. This should give you a good baseline to go off

2

solved Better way to write this javascript filter code? [closed]