Skip to content

Commit

Permalink
Updated ts workshop (#15)
Browse files Browse the repository at this point in the history
Updated last question

Issue: /
Reviewer: PR
  • Loading branch information
Meloyg authored Apr 13, 2022
1 parent 96beb67 commit 623c55b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
6 changes: 4 additions & 2 deletions 8. Typescript workshop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Create a Interface called `PersonInterface` that has the following properties:
The parameter `age` could be optional.

### Exercise 6:
Create a Generic function called `sortAndConcat` that takes two arrays of any type and returns a new array with the elements sorted and concatenated. The function should return a new array.
Create a Generic function called `sortAndConcat` that takes two arrays of any type and returns a new array with the elements sorted and concatenated. The function should return a new array. **Notice: You should also remove any duplicate elements from the new array.**

> **Hint**: You can use `<T>` to specify the type of the generic parameter.
Expand All @@ -93,7 +93,9 @@ Once you have completed the assignment, you can run the tests by running the fol
$ npm test
```

If the tests pass, that means you have completed the assignment correctly :)
If the tests pass, that means you have completed the assignment correctly :) You can refer to the images below to see what the correct output looks like.

![picture 1](../images/tsTest.png)

## Extras
If you would like too see the compiled output of the TypeScript compiler, you can run the following command in the command line:
Expand Down
2 changes: 1 addition & 1 deletion 8. Typescript workshop/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Student extends Person {}
// - age (optional)
interface PersonInterface {}

// Question 6 Create a Generic function to sort arrays of any type and concat them together.
// Question 6 Create a Generic function to sort arrays of any type and concat them together. Any duplicates should be removed.
function sortAndConcat() {}

// Export the functions above so that they can be used in the tests.
Expand Down
18 changes: 17 additions & 1 deletion 8. Typescript workshop/src/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,24 @@ describe("testing index file", () => {

describe("testing index file", () => {
test("Question6 case2", () => {
const list1 = [1, 2, 3, 2];
const list2 = [3, 5, 6, 7];
expect(sortAndConcat(list1, list2)).toEqual([1, 2, 3, 5, 6, 7]);
});
});

describe("testing index file", () => {
test("Question6 case3", () => {
const list1 = ["v", "a", "r"];
const list2 = ["a", "b", "c"];
expect(sortAndConcat(list1, list2)).toEqual(["a", "a", "b", "c", "r", "v"]);
expect(sortAndConcat(list1, list2)).toEqual(["a", "b", "c", "r", "v"]);
});
});

describe("testing index file", () => {
test("Question6 case4", () => {
const list1 = ["a"]
const list2 = [null];
expect(sortAndConcat(list1, list2)).toEqual(["a", null]);
});
});
Binary file added images/tsTest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 623c55b

Please sign in to comment.