Skip to content

Commit

Permalink
Array.diff
Browse files Browse the repository at this point in the history
  • Loading branch information
PheRum committed May 15, 2024
1 parent 6c78e92 commit e12e666
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 2 deletions.
17 changes: 17 additions & 0 deletions 6_kyu/Array.diff/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## Array.diff

https://www.codewars.com/kata/523f5d21c841566fde000009/train/typescript

Your goal in this kata is to implement a difference function, which subtracts one list from another and returns the result.

It should remove all values from list a, which are present in list b keeping their order.

```
array_diff({1, 2}, 2, {1}, 1, *z) == {2} (z == 1)
```

If a value is present in `b`, all of its occurrences must be removed from the other:

```
array_diff({1, 2, 2, 2, 3}, 5, {2}, 1, *z) == {1, 3} (z == 2)
```
10 changes: 10 additions & 0 deletions 6_kyu/Array.diff/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { arrayDiff } from "./index";

describe("Basic tests", () => {
it("Basic test should work", () => {
expect(arrayDiff([], [4, 5])).toStrictEqual([]);
expect(arrayDiff([3, 4], [3])).toStrictEqual([4]);
expect(arrayDiff([1, 8, 2], [])).toStrictEqual([1, 8, 2]);
expect(arrayDiff([1, 2, 3], [1, 2])).toStrictEqual([3]);
});
});
3 changes: 3 additions & 0 deletions 6_kyu/Array.diff/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function arrayDiff(a: number[], b: number[]): number[] {
return a.filter((el) => !b.includes(el));
}
1 change: 1 addition & 0 deletions 6_kyu/_example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## Example
7 changes: 7 additions & 0 deletions 6_kyu/_example/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { example } from "./index";

describe("Tests", () => {
it("example", () => {
expect(example(1, 1)).toBe(2);
});
});
3 changes: 3 additions & 0 deletions 6_kyu/_example/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function example(m: number, n: number) {
return m + n;
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

### Katas solved

`Total`: 25 \
`Total`: 26 \
`8_kyu`: 25 \
`7_kyu`: 0 \
`6_kyu`: 0 \
`6_kyu`: 1 \
`5_kyu`: 0 \
`4_kyu`: 0 \
`3_kyu`: 0 \
Expand Down

0 comments on commit e12e666

Please sign in to comment.