Skip to content

Commit

Permalink
Removing Elements
Browse files Browse the repository at this point in the history
  • Loading branch information
PheRum committed Jun 14, 2024
1 parent 78b237b commit 81d8c4b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
10 changes: 10 additions & 0 deletions 8_kyu/Removing Elements/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## Removing Elements

https://www.codewars.com/kata/5769b3802ae6f8e4890009d2

Take an array and remove every second element from the array. Always keep the first element and start removing with the next element.

Example:
["Keep", "Remove", "Keep", "Remove", "Keep", ...] --> ["Keep", "Keep", "Keep", ...]

None of the arrays will be empty, so you don't have to worry about that!
10 changes: 10 additions & 0 deletions 8_kyu/Removing Elements/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { removeEveryOther } from "./index";

describe("Tests", () => {
it("example", () => {
expect(removeEveryOther(["Hello", "Goodbye", "Hello Again"])).toEqual(["Hello", "Hello Again"]);
expect(removeEveryOther([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])).toEqual([1, 3, 5, 7, 9]);
expect(removeEveryOther([[1, 2]])).toEqual([[1, 2]]);
expect(removeEveryOther([["Goodbye"], { Great: "Job" }])).toEqual([["Goodbye"]]);
});
});
3 changes: 3 additions & 0 deletions 8_kyu/Removing Elements/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function removeEveryOther<T>(arr: T[]): T[] {
return arr.filter((el, idx) => idx % 2 === 0);
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

### Katas solved

`Total`: 81 \
`8_kyu`: 64 \
`Total`: 82 \
`8_kyu`: 65 \
`7_kyu`: 13 \
`6_kyu`: 4 \
`5_kyu`: 0 \
Expand Down
1 change: 0 additions & 1 deletion kata.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
8 kyu - Removing Elements - https://www.codewars.com/kata/5769b3802ae6f8e4890009d2
8 kyu - Remove duplicates from list - https://www.codewars.com/kata/57a5b0dfcf1fa526bb000118
8 kyu - A Needle in the Haystack - https://www.codewars.com/kata/56676e8fabd2d1ff3000000c
8 kyu - Convert a string to an array - https://www.codewars.com/kata/57e76bc428d6fbc2d500036d
Expand Down

0 comments on commit 81d8c4b

Please sign in to comment.