-
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
7 changed files
with
43 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,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) | ||
``` |
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,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]); | ||
}); | ||
}); |
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 arrayDiff(a: number[], b: number[]): number[] { | ||
return a.filter((el) => !b.includes(el)); | ||
} |
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 @@ | ||
## Example |
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,7 @@ | ||
import { example } from "./index"; | ||
|
||
describe("Tests", () => { | ||
it("example", () => { | ||
expect(example(1, 1)).toBe(2); | ||
}); | ||
}); |
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 example(m: number, n: number) { | ||
return m + n; | ||
} |
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