News for hackers. Stuff that matters.
Re:Math.min(Math.max(num, min), max) by yesbabyyes on Thursday August 20, 2020 @10:57AM (#24223944)
Good point, for those who need to implement a slick compareFunction for numbers, Math.sign is great:

  [min, num, max].sort((a, b) => Math.sign(a - b))[1]
An entirely different alternative is poor man's match:

  switch (true) {
  case num > max: return max;
  case num < min: return min;
  default: return num;
  }
Re:Math.min(Math.max(num, min), max) by recursive on Thursday August 20, 2020 @12:50PM (#24225338)
Why sign though? I always write my sorts like this.

    .sort((a, b) => a - b)
Re:Math.min(Math.max(num, min), max) by saagarjha on Thursday August 20, 2020 @02:38PM (#24226859)
Is there a better way to grab a reference to the subtraction operator?
Re:Math.min(Math.max(num, min), max) by recursive on Thursday August 20, 2020 @03:39PM (#24227796)
I assume you're referring to a point-free reference.

Only by defining a `const subtract = (a, b) => a - b;`, which isn't really point-free.

Or by using a different language.