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

verify-array-sort

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

verify-array-sort

A package to verify if the array is sorted in ascending or descending order

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
0
Created
Source

verify-array-sort

This Node.js package provides a function to check if an array is sorted in ascending or descending order.

Installation

npm install verify-array-sort

Usage

Import using require

const isSorted = require('verify-array-sort');

Import using import

import isSorted from 'verify-array-sort'
// Check if an array of numbers is sorted in ascending order
const numbers = [1, 2, 3, 4, 5];
console.log(isSorted(numbers, 'ascending')); // Output: true

// Check if an array of numbers is sorted in descending order
const numbersDesc = [5, 4, 3, 2, 1];
console.log(isSorted(numbersDesc, 'descending')); // Output: true

// Check if an array of strings is sorted in ascending order (lexicographically)
const strings = ['apple', 'banana', 'cherry'];
console.log(isSorted(strings, 'ascending')); // Output: true

// Check if an array of dates is sorted in ascending order
const dates = [new Date('2023-01-01'), new Date('2023-02-01'), new Date('2023-03-01')];
console.log(isSorted(dates, 'ascending')); // Output: true

// Example with unsorted array
const unsortedNumbers = [1, 3, 2, 4];
console.log(isSorted(unsortedNumbers, 'ascending')); // Output: false 

API

isSorted(arr, order)

  • arr: The array to check.
  • order: The order to check for ('ascending' or 'descending').

Returns:

  • true if the array is sorted according to the specified order.
  • false otherwise

Supported Data Types

  • Numbers
  • Strings
  • Dates

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Keywords

array

FAQs

Package last updated on 15 Jan 2025

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