New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

stacksort

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stacksort

A simple sorting algorithm implemented with stacks

latest
Source
npmnpm
Version
0.0.4
Version published
Maintainers
1
Created
Source

StackSort

StackSort is a simple sorting algorithm implemented with stacks.

var StackSort = require('StackSort')

var toSort = [5, 2, 3, 1, 8]

var sorted = StackSort(toSort)

Installation

$ npm install stacksort

Examples

Sorting Integer arrays

var toSort = [3, 2, 1, 8, 5]

// Ascending order
StackSort(toSort)
// Descending order
StackSort(toSort, function(a, b){
  return b - a
})

Sorting Alphabets arrays

const Alphabets = 'abcdefghijklmnopqrstuvwxyz'
var toSort = ['d', 'c', 'b', 'a', 'e']

// Ascending order
StackSort(toSort, function (a, b) {
  return Alphabets.indexOf(a) - Alphabets.indexOf(b)
})
// Descending order
StackSort(toSort, function (a, b) {
  return Alphabets.indexOf(b) - Alphabets.indexOf(a)
})

Documentation

Stacksort( array [, compareFn] )

StackSort takes in an array as the first argument, an optional comparison function as the second argument, and returns the sorted array.

If no comparison function is provided, the comparison function defaults to the following:

function (a, b) {
  return a - b
}

Test

$ npm install
$ npm test

Keywords

algorithms

FAQs

Package last updated on 04 Apr 2017

Did you know?

Socket

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.

Install

Related posts