signal-desktop/ts/util/isSorted.ts

14 lines
345 B
TypeScript
Raw Normal View History

2021-10-14 21:19:50 +00:00
// 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;
}