Skip to content

Commit

Permalink
Enumerable Magic #1 - True for All?
Browse files Browse the repository at this point in the history
  • Loading branch information
PheRum committed May 18, 2024
1 parent a177de6 commit 64b8e46
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
15 changes: 15 additions & 0 deletions 8_kyu/Enumerable Magic #1 - True for All?/README.md
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
```
8 changes: 8 additions & 0 deletions 8_kyu/Enumerable Magic #1 - True for All?/index.test.ts
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);
});
});
3 changes: 3 additions & 0 deletions 8_kyu/Enumerable Magic #1 - True for All?/index.ts
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);
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

### Katas solved

`Total`: 34 \
`8_kyu`: 33 \
`Total`: 35 \
`8_kyu`: 34 \
`7_kyu`: 0 \
`6_kyu`: 1 \
`5_kyu`: 0 \
Expand Down

0 comments on commit 64b8e46

Please sign in to comment.