signal-desktop/ts/util/isSorted.ts
2021-10-14 16:19:50 -05:00

13 lines
345 B
TypeScript

// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
export function isSorted(list: Iterable<number>): boolean {
let previousItem: undefined | number;
for (const item of list) {
if (previousItem !== undefined && item < previousItem) {
return false;
}
previousItem = item;
}
return true;
}