Skip to content

Commit 5af48af

Browse files
committed
chore: make findLast simple
1 parent 152be95 commit 5af48af

File tree

2 files changed

+1
-11
lines changed

2 files changed

+1
-11
lines changed

test/integration/node-specific/abort_signal.test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@ import { TLSSocket } from 'node:tls';
33
import * as util from 'node:util';
44

55
import { expect } from 'chai';
6-
import * as semver from 'semver';
76
import * as sinon from 'sinon';
87

98
import {
109
type AbstractCursor,
1110
AggregationCursor,
12-
type AutoEncryptionOptions,
13-
ClientEncryption,
1411
type Collection,
1512
type ConnectionClosedEvent,
1613
type Db,

test/tools/utils.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -710,14 +710,7 @@ export function findLast(
710710
thisArg?: any
711711
): unknown | undefined {
712712
if (typeof array.findLast === 'function') return array.findLast(predicate, thisArg);
713-
714-
for (let i = array.length - 1; i >= 0; i--) {
715-
if (predicate.call(thisArg, array[i], i, array)) {
716-
return array[i];
717-
}
718-
}
719-
720-
return undefined;
713+
return array.slice().reverse().find(predicate, thisArg);
721714
}
722715

723716
// Node.js 16 doesn't make this global, but it can still be obtained.

0 commit comments

Comments
 (0)