Not Equal
Computes an element-wise comparison (not equal) of an array.
Installation
$ npm install compute-neq
For use in the browser, use browserify.
Usage
To use the module,
var neq = ;
neq( arr, x[, opts] )
Computes an element-wise comparison (not equal) for each input array
element. x
may either be an array
of equal length or a single value (of any type).
The function returns an array
with length equal to that of the input array
. Each output array
element is either 0
or 1
. A value of 1
means that an element is not equal to a compared value and 0
means that an element is equal to a compared value.
var arr = 5 3 8 3 2out;// Single comparison value:out = ;// returns [ 1, 0, 1, 0, 1 ]// Array of comparison values:out = ;// returns [ 0, 1, 0, 1, 1 ]
By default, the function enforces type equality. To turn off type equality, set the strict
options flag to false
.
var arr = 1 0 3 null undefinedcompare = true false 2 0 1out;out = ;// returns [ 1, 1, 1, 1, 1 ];out = ;// returns [ 0, 0, 1, 1, 1 ]
By default, if provided a comparison array
which has a length equal to the input array
length, the function assumes an element-by-element comparison. To turn off element-by-element comparison for equal length arrays
, set the array
options flag to true
.
var el = 1 2arr = el nullout;out = ;// returns [ 1, 1 ];out = ;// returns [ 0, 1 ];
Notes
- Currently, this function only computes shallow inequality and does not compute deep inequality when comparing
arrays
orobjects
.
Examples
var neq =sum = ;// Simulate some data...var data = 100 ;for var i = 0; i < datalength; i++data i = Math;var out = ;// Count the number of values not equal to 10...var count = ;console;
To run the example code from the top-level application directory,
$ node ./examples/index.js
Tests
Unit
Unit tests use the Mocha test framework with Chai assertions. To run the tests, execute the following command in the top-level application directory:
$ make test
All new feature development should have corresponding unit tests to validate correct functionality.
Test Coverage
This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:
$ make test-cov
Istanbul creates a ./reports/coverage
directory. To access an HTML version of the report,
$ make view-cov
License
Copyright
Copyright © 2014. Athan Reines.