Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- a <=> b :=
- if a < b then return -1
- if a = b then return 0
- if a > b then return 1
- function spaceship(val1, val2) {
- if ((val1 === null || val2 === null) || (typeof val1 != typeof val2)) {
- return null;
- }
- if (typeof val1 === 'string') {
- return (val1).localeCompare(val2);
- }
- else {
- if (val1 > val2) { return 1 }
- else if (val1 < val2) { return -1 }
- return 0;
- }
- }
- function spaceship(val1, val2) {
- if ((val1 === null || val2 === null) || (typeof val1 != typeof val2)) {
- return null;
- }
- if (typeof val1 === 'string') {
- return (val1).localeCompare(val2);
- } else {
- if (val1 > val2) {
- return 1;
- } else if (val1 < val2) {
- return -1;
- }
- return 0;
- }
- }
- Math.sign(a - b);
Add Comment
Please, Sign In to add comment