We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent c222fcd commit 5aa5050Copy full SHA for 5aa5050
2 files changed
chapter-7/ex1.ts
@@ -0,0 +1,14 @@
1
+function arrayIntersection(arr1: number[], arr2: number[]): number[] {
2
+ let mappedArray = new Map<number, boolean>();
3
+ for (const num of arr1) {
4
+ mappedArray.set(num, true);
5
+ }
6
+ let intersection: number[] = [];
7
+
8
+ for (const num of arr2) {
9
+ if (mappedArray.has(num)) {
10
+ intersection.push(num);
11
12
13
+ return intersection;
14
+}
chapter-7/ex2.ts
@@ -0,0 +1,11 @@
+function findFirstDuplicate(array: string[]): string {
+ const hash = new Map<string, boolean>()
+ for (const str of array) {
+ if (hash.has(str)) {
+ return str
+ hash.set(str, true)
+ return 'No duplicates found'
0 commit comments