Hacker News new | ask | show | jobs
by Too 3192 days ago
It's also easy to implement as a one liner

   var atleastTwo = function(x){return function(){return Math.max(2,x);}
Even simpler with typescript

   var atLeastTwo = (x) => (() => Math.max(2, x))
1 comments

ES6

    const atLeastTwo = x => Math.max(2,x)
his is a function that returns a function, i.e. you'd need to call atLeastTwo(x)(); to get a result, yours is just a function. in es6 the equivalent thing to what he wrote would be:

    const atLeastTwo = x => () => Math.max(2, x);