UNPKG

everyutil

Version:

A comprehensive library of lightweight, reusable utility functions for JavaScript and TypeScript, designed to streamline common programming tasks such as string manipulation, array processing, date handling, and more.

22 lines (21 loc) 593 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isSorted = void 0; /** * Verifies if the array is sorted. * @author @dailker * @template T * @param {T[]} array * @param {'asc'|'desc'} [order='asc'] * @returns {boolean} */ function isSorted(array, order = 'asc') { for (let i = 1; i < array.length; i++) { if (order === 'asc' && array[i - 1] > array[i]) return false; if (order === 'desc' && array[i - 1] < array[i]) return false; } return true; } exports.isSorted = isSorted;