-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
4 changed files
with
28 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
## Enumerable Magic #1 - True for All? | ||
|
||
Create a method all which takes two params: | ||
|
||
- a sequence | ||
- a function (function pointer in C) | ||
|
||
and returns true if the function in the params returns true for every element in the sequence. Otherwise, it should return false. If the sequence is empty, it should return true, since technically nothing failed the test. | ||
|
||
### Example | ||
|
||
``` | ||
all((1, 2, 3, 4, 5), greater_than_9) -> false | ||
all((1, 2, 3, 4, 5), less_than_9) -> True | ||
``` |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { all } from "./index"; | ||
|
||
describe("Tests", () => { | ||
it("all", () => { | ||
expect(all([1, 2, 3, 4, 5], (v) => v < 9)).toBe(true); | ||
expect(all([1, 2, 3, 4, 5], (v) => v > 9)).toBe(false); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function all(arr: number[], fun: (n: number) => boolean): boolean { | ||
return arr.every(fun); | ||
} |
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