-
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
5 changed files
with
25 additions
and
3 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,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! |
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 { 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"]]); | ||
}); | ||
}); |
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 removeEveryOther<T>(arr: T[]): T[] { | ||
return arr.filter((el, idx) => idx % 2 === 0); | ||
} |
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
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