Skip to content

Instantly share code, notes, and snippets.

@NullDev
Last active February 3, 2022 19:23
Show Gist options
  • Save NullDev/2b0c108b252a06033cb7ad4d81a847b3 to your computer and use it in GitHub Desktop.
Save NullDev/2b0c108b252a06033cb7ad4d81a847b3 to your computer and use it in GitHub Desktop.
A weird implementation of PHP's Spaceship operator in JavaScript
Number.prototype["<=>"] = function(x){
return Math.sign(this - x);
}
var result = 5 ["<=>"] `4`;
console.log(result);
// https://jsfiddle.net/veyar51m/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment