-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d696e8e
commit 52d793d
Showing
4 changed files
with
19 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,10 @@ | ||
import {iteratorToArray} from "../../../helpers/iterator-to-array"; | ||
import {max as phpMax} from "locutus/php/math"; | ||
|
||
export function max(...values: any[]): Promise<any> { | ||
export function max(...values: Array<any>): Promise<any> { | ||
if (values.length === 1) { | ||
values = values[0]; | ||
} | ||
|
||
let array = iteratorToArray(values); | ||
|
||
array.sort((a: any, b: any) => { | ||
return a < b ? 1 : -1; | ||
}); | ||
|
||
return Promise.resolve(array[0]); | ||
return Promise.resolve(phpMax(iteratorToArray(values))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,10 @@ | ||
import {iteratorToArray} from "../../../helpers/iterator-to-array"; | ||
import {min as phpMin} from "locutus/php/math"; | ||
|
||
export function min(...values: Array<any>): Promise<any> { | ||
if (values.length === 1) { | ||
values = values[0]; | ||
} | ||
|
||
let array = iteratorToArray(values); | ||
|
||
array.sort(); | ||
|
||
return Promise.resolve(array[0]); | ||
return Promise.resolve(phpMin(iteratorToArray(values))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
import * as tape from 'tape'; | ||
import {min} from "../../../../../../../../src/lib/extension/core/functions/min"; | ||
|
||
tape('min', (test) => { | ||
test.test('supports multiple parameters', async (test) => { | ||
test.same(await min(1, 3, 2), 1); | ||
|
||
test.end(); | ||
}); | ||
tape('min', async (test) => { | ||
test.same(await min(1, 3, 2), 1); | ||
test.same(await min([1, 3, 2]), 1); | ||
test.same(await min(0, 'a', 2), 0); | ||
test.same(await min('b', 'a'), 'a'); | ||
test.same(await min('b', 'a', 2), 'a'); | ||
test.same(await min('b', 'a', -2), -2); | ||
test.same(await min(-5, 5, 10, -10, 20, -20), -20); | ||
|
||
test.end(); | ||
}); |