Skip to content

Commit

Permalink
Only Duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
PheRum committed Jun 20, 2024
1 parent af67470 commit a62dfaf
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
11 changes: 11 additions & 0 deletions 6_kyu/Only Duplicates/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Only Duplicates

https://www.codewars.com/kata/5a1dc4baffe75f270200006b

Given a string, remove any characters that are unique from the string.

Example:

input: "abccdefee"

output: "cceee"
10 changes: 10 additions & 0 deletions 6_kyu/Only Duplicates/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { onlyDuplicates } from "./index";

describe("Tests", () => {
it("example", () => {
expect(onlyDuplicates("abccdefee")).toBe("cceee");
expect(onlyDuplicates("hello")).toBe("ll");
expect(onlyDuplicates("colloquial")).toBe("ollol");
expect(onlyDuplicates("foundersandcoders")).toBe("ondersndoders");
});
});
16 changes: 16 additions & 0 deletions 6_kyu/Only Duplicates/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export function onlyDuplicates(str: string): string {
const array: string[] = str.split("");
const hashTable: { [key: string]: number } = {};

array.forEach((item) => {
if (hashTable[item]) {
hashTable[item]++;
} else {
hashTable[item] = 1;
}
});

const dublicates = array.filter((item) => hashTable[item] > 1);

return dublicates.join("");
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

### Katas solved

`Total`: 115 \
`Total`: 116 \
`8_kyu`: 92 \
`7_kyu`: 15 \
`6_kyu`: 8 \
`6_kyu`: 9 \
`5_kyu`: 0 \
`4_kyu`: 0 \
`3_kyu`: 0 \
Expand Down

0 comments on commit a62dfaf

Please sign in to comment.