File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -214,6 +214,34 @@ function internalMaximum<T>(array: ArrayLike<T>, compare: Comparator<T>): T | nu
214
214
return result ;
215
215
}
216
216
217
+ export function minimum < T extends string | number | boolean > ( array : ArrayLike < T > ) : T | null ;
218
+ export function minimum < T > ( array : ArrayLike < T > , compare : Comparator < T > ) : T | null ;
219
+ export function minimum < T > ( array : ArrayLike < T > , compare : Comparator < any > = defaultCompare ) : T | null {
220
+ return internalMinimum ( array , compare ) ;
221
+ }
222
+
223
+ export function minimumFn < T extends string | number | boolean > ( ) : ( array : ArrayLike < T > ) => T | null ;
224
+ export function minimumFn < T > ( compare : Comparator < T > ) : ( array : ArrayLike < T > ) => T | null ;
225
+ export function minimumFn < T > ( compare : Comparator < any > = defaultCompare ) : ( array : ArrayLike < T > ) => T | null {
226
+ return array => internalMinimum ( array , compare ) ;
227
+ }
228
+
229
+ function internalMinimum < T > ( array : ArrayLike < T > , compare : Comparator < T > ) : T | null {
230
+ if ( array . length === 0 ) {
231
+ return null ;
232
+ }
233
+
234
+ let result = array [ 0 ] ;
235
+
236
+ for ( let i = 1 ; i < array . length ; ++ i ) {
237
+ if ( compare ( array [ i ] , result ) < 0 ) {
238
+ result = array [ i ] ;
239
+ }
240
+ }
241
+
242
+ return result ;
243
+ }
244
+
217
245
export function keyBy < T > ( array : ArrayLike < T > ,
218
246
f : ( element : T ) => string ) : Dictionary < T [ ] > {
219
247
const dictionary = { } as Dictionary < T [ ] > ;
You can’t perform that action at this time.
0 commit comments