0.1.0 • Published 4 years ago
spaceship.js v0.1.0
What is it for?
Useful for sorting strings in JavaScript using the new sort
function and to
use in some switch
statements making the code cleaner.
It acts like PHP's spaceship (<=>
) operator.
How does it work?
- The
spaceship
function takes two arguments; - If the left hand side argument is LESS THAN the right side argument, the function returns -1;
- If the left hand side argument is EQUAL the right side argument, the function returns 0;
- If the left hand side argument is GREATER THAN the right side argument, the function returns 1;
Usage
Importing / requiring the function
You just need to require the module like this:
const spaceship = require("spaceship").default;
Or like this:
import spaceship from "spaceship";
Then use it:
spaceship("IE", "Safari"); // -1
spaceship("cookie", "cookie"); // 0
spaceship("house", "car"); // 1
That's all.
0.1.0
4 years ago
0.0.8-beta
5 years ago
0.0.3-beta
5 years ago
0.0.2-beta
5 years ago
0.0.1-beta
5 years ago