
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
compute-issorted
Advanced tools
Returns a boolean indicating if an input array is sorted.
$ npm install compute-issorted
For use in the browser, use browserify.
To use the module,
var issorted = require( 'compute-issorted' );
Returns a boolean indicating if an input array is sorted.
var bool = issorted( [ 2, 6, 13, 5 ] );
// returns false
By default, the function checks if the input array is sorted in ascending order. To impose a different order, provide a comparator function.
// Descending order...
function comparator( a, b ) {
return b - a;
}
var bool = issorted( [ 13, 6, 5, 2 ], comparator );
// returns true
The comparator function should behave the same as a comparator provided to arr.sort().
The comparator should take two arguments: a and b, where a and b are consecutive array elements. If the comparator returns a numeric value less than or equal to 0, consecutive elements are considered sorted; otherwise, issorted returns false.
var issorted = require( 'compute-issorted' ),
shuffle = require( 'compute-shuffle' );
// Simulate some data...
var data = new Array( 5 );
for ( var i = 0; i < data.length; i++ ) {
data[ i ] = i;
}
// Randomly shuffle the data and check if sorted...
var bool;
console.log( 'Data\t\tSorted?' );
for ( var j = 0; j < 100; j++ ) {
shuffle( data );
bool = issorted( data );
console.log( data.join( ',' )+'\t'+bool );
}
To run the example code from the top-level application directory,
$ node ./examples/index.js
This function runs in linear time: O(N), where N is the input array length.
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.
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
Copyright © 2014. Athan Reines.
FAQs
Returns a boolean indicating if an input array is sorted.
We found that compute-issorted demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.