Socket
Socket
Sign inDemoInstall

compare

Package Overview
Dependencies
0
Maintainers
3
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.1 to 2.0.0

LICENSE

16

index.js

@@ -1,15 +0,3 @@

module.exports = compare
function compare(array, comparator) {
var l = array.length
var a
for (var i = 0; i < l; i += 1) {
a = array[i]
for (var j = 0; j < l; j += 1) {
if (i === j) continue
if (!comparator(a, array[j], i, j)) return false
}
}
return true
module.exports = function (a, b) {
return a < b ? -1 : a > b ? 1 : 0
}
{
"name": "compare",
"version": "0.0.1",
"description": "ERROR: No README.md file found!",
"version": "2.0.0",
"description": "Compare primitives the right way (using `<`, `>` and `==`)",
"main": "index.js",
"scripts": {
"test": "node test.js"
},
"dependencies": {},
"devDependencies": {},
"scripts": {},
"repository": {
"type": "git",
"url": "git://github.com/hughsk/compare.git"
"url": "git+https://github.com/emilbayes/compare.git"
},
"author": "Hugh Kennedy <hughskennedy@gmail.com> (http://hughskennedy.com/)",
"license": "MIT",
"keywords": [
"compare",
"all",
"elements",
"array",
"comparison"
"cmpstr",
"string",
"number",
"numeric",
"sort",
"stable",
"ascii"
],
"devDependencies": {
"tape": "~1.0.4"
}
"author": "Emil Bay <github@tixz.dk>",
"license": "ISC",
"bugs": {
"url": "https://github.com/emilbayes/compare/issues"
},
"homepage": "https://github.com/emilbayes/compare#readme"
}

@@ -1,19 +0,50 @@

# compare #
# `compare`
Compare each element in an array with every other element in the array.
![100-correct](https://img.shields.io/badge/Correct%20-100%25-brightgreen.svg?style=flat)
## Installation ##
> Compare primitives the right way (using `<`, `>` and `==`)
``` bash
npm install compare
This module does the right thing with numbers and ascii strings.
Normally `String.prototype.localeCompare` is recommended for strings,
but that can have nasty side effects on some machines, eg.
```js
'cu'.localeCompare('cs', 'hu')
```
## Usage ##
Compare the above in stock node (which doesn't come with `Intl`) and
a browser of your choice (which most likely has `Intl` support).
``` javascript
## Usage
```js
var compare = require('compare')
[1, 2, 10].sort() // [1, 10, 2]
[1, 2, 10].sort(compare) // [1, 2, 10]
compare([1, 1, 1, 1], function(a, b) { return a === b }) // true
compare([1, 2, 3, 4], function(a, b) { return a !== b }) // true
compare([1, 2, 3, 3], function(a, b) { return a !== b }) // false
// Below is sorted correctly according to Hungarian, but runtimes without Intl
// support will reorder them
['cu', 'cs'].sort((a, b) => a.localeCompare(b, 'hu'))
['cu', 'cs'].sort(compare) // This will always sort the same
```
## API
### `compare(a, b)`
Standard `Array.prototype.sort(cmp)` function signature. If `a > b` return `1`,
if `a < b` return `-1`, otherwise return `0`
## Credit
Thanks to [`hughsk`](https://github.com/hughsk) for the npm name!
## Install
```sh
npm install compare
```
## License
[ISC](LICENSE)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc