Skip to content

Commit ba271d2

Browse files
committed
Feat/Adds a typescript version of the java methods.
1 parent 681451e commit ba271d2

File tree

1 file changed

+43
-8
lines changed

1 file changed

+43
-8
lines changed

lesson_11/arrays_ts/src/lesson11.ts

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,50 @@
1+
12
/**
2-
* Provide the solution to LeetCode 1929 here:
3-
* https://leetcode.com/problems/concatenation-of-array
4-
*/
3+
* Provide the solution to LeetCode 1929 here:
4+
* https://leetcode.com/problems/concatenation-of-array
5+
*/
56
export function getConcatenation(nums: number[]): number[] {
6-
return [];
7+
const n = nums.length; //Creates a variable named n that is the length of nums
8+
const ans: number[] = new Array(2 * n); //Creates a new array that is double the size of n
9+
10+
11+
for(let i = 0; i < n; ++i) {
12+
ans[i] = nums[i];
13+
ans[i + n] = nums[i];
14+
15+
16+
}
17+
return ans;
718
}
819

20+
921
/**
10-
* Provide the solution to LeetCode 2942 here:
11-
* https://leetcode.com/problems/find-words-containing-character/
12-
*/
22+
* Provide the solution to LeetCode 2942 here:
23+
* https://leetcode.com/problems/find-words-containing-character/
24+
*/
1325
export function findWordsContaining(words: string[], x: string): number[] {
14-
return [];
26+
const elListo: number[] = [] //creates a new array named elListo
27+
28+
29+
//Runs a loop that will iterate through each character in the String.
30+
for (let i = 0; i < words.length; ++i) {
31+
if (words[i].includes(x)) { //Checks to see if the word inclues the char 'x'
32+
elListo.push(i); //Pushes the index of i if it is true that the word contains that character
33+
34+
}
35+
} return elListo; //Will return the Array elListo
1536
}
37+
38+
39+
//Test Cases
40+
41+
42+
const nums: number[] = [1, 2 , 3, 4]; //Array of numbers based on test case
43+
const result: number[] = getConcatenation(nums);
44+
console.log(result.join(" "))//Prints the test result out for the fet concatentaition method
45+
46+
47+
const words: string[] = ["leet", "code", "hello", "world"]; //Array of strings based on test case
48+
const x: string = 'e'; //Calls for a specific char
49+
console.log(findWordsContaining(words, x));
50+

0 commit comments

Comments
 (0)