Skip to content

Commit

Permalink
Merge pull request #2 from EshaanAgg/main
Browse files Browse the repository at this point in the history
Improvements
  • Loading branch information
EshaanAgg authored Apr 6, 2023
2 parents 5b89823 + 82d9521 commit 56a3ad7
Show file tree
Hide file tree
Showing 9 changed files with 479 additions and 405 deletions.
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,45 @@ To run the project:
4. Solve the tasks!
5. You can view your progress by running the command `npm run test` and then viewing the file `index.html`!
6. When done, push the same to GitHub and create a Pull Request to submit your work.

## How to implement assignments

Task modules are located in the `src` folder. Each module consists of several tasks (functions you need to complete) for specified topic. Each task/fucntion looks mostly like the following:

```javascript
/**
* Returns the result of concatenation of two strings.
*
* @param {string} value1
* @param {string} value2
* @return {string}
*
* @example
* 'aa', 'bb' => 'aabb'
* 'aa','' => 'aa'
* '', 'bb' => 'bb'
*/
function concatenateStrings(value1, value2) {
throw new Error("Not implemented");
}
```

- Read the task description in the comment above the function. Try to understand the idea. The comments clearly document what the inputs to the function are, and what should it's return value be.
- Remove the throwing error line from function body

```javascript
throw new Error("Not implemented");
```

and run the unit tests again using `npm run test`.

- Find the test corresponding to the function in the automatically opened `Test Results` page. You can see the `points` associated with the particular test on the webpage.
- Clicking on the header corresponging to the test would also give you additonal information about the failing cases!

![Test Information Example](assets/test_example.png)

For example, in this screenshot, we can see that the `findElement` function is failing on the call `findElement(["Array", "Number", "string"], "Date")` as the same is returning the value `1`, while the value `-1` was expected!

- Implement the function using your JS knowledge and verify your solution by running tests until the failed test passes (becomes green).
- Even after your solution passes, try to refactor it! Try to make your code as pretty and simple as possible keeping the tests green!
- You can see your total score in the tests in the command line where you ran the `npm run test` command. You can include a screenshot of the same while submitting the pull request.
Binary file added assets/test_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion jest-html-reporters-attach/index/result.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "js_assignment",
"version": "1.0.0",
"description": "",
"description": "Assignment to check basic familiarity with JS functions and primitives!",
"main": "index.js",
"directories": {
"test": "tests"
Expand All @@ -11,14 +11,14 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/vaibhav-1508/js_assignment.git"
"url": "git+https://github.com/eshaanagg/js_assignment.git"
},
"author": "EshaanAgg",
"license": "ISC",
"bugs": {
"url": "https://github.com/vaibhav-1508/js_assignment/issues"
"url": "https://github.com/eshaanagg/js_assignment/issues"
},
"homepage": "https://github.com/vaibhav-1508/js_assignment#readme",
"homepage": "https://github.com/eshaanagg/js_assignment#readme",
"devDependencies": {
"jest": "^29.5.0",
"jest-html-reporters": "^3.1.4"
Expand Down
60 changes: 31 additions & 29 deletions tests/array.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,40 @@ const {
getItemsSum,
} = require("../src/array");

test(`(5 pts) Testing findElement`, () => {
expect(findElement(["Ace", 10, true], 10)).toEqual(1);
expect(findElement(["Array", "Number", "string"], "Date")).toEqual(-1);
expect(findElement([0, 1, 2, 3, 4, 5], 5)).toEqual(5);
});
describe(`Arrays`, () => {
test(`(5 pts) Testing findElement`, () => {
expect(findElement(["Ace", 10, true], 10)).toEqual(1);
expect(findElement(["Array", "Number", "string"], "Date")).toEqual(-1);
expect(findElement([0, 1, 2, 3, 4, 5], 5)).toEqual(5);
});

test(`(2 pts) Testing doubleArray`, () => {
expect(doubleArray(["Ace", 10, true])).toEqual(["Ace", 10, true, "Ace", 10, true]);
expect(doubleArray([0, 1, 2, 3, 4, 5])).toEqual([0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5]);
expect(doubleArray([])).toEqual([]);
});
test(`(2 pts) Testing doubleArray`, () => {
expect(doubleArray(["Ace", 10, true])).toEqual(["Ace", 10, true, "Ace", 10, true]);
expect(doubleArray([0, 1, 2, 3, 4, 5])).toEqual([0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5]);
expect(doubleArray([])).toEqual([]);
});

test(`(4 pts) Testing getArrayOfPositives`, () => {
expect(getArrayOfPositives([0, 1, 2, 3, 4, 5])).toEqual([1, 2, 3, 4, 5]);
expect(getArrayOfPositives([0, 1, 2, 3, 4, 5])).toEqual([0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5]);
expect(getArrayOfPositives([])).toEqual([]);
});
test(`(4 pts) Testing getArrayOfPositives`, () => {
expect(getArrayOfPositives([0, 1, 2, 3, 4, 5])).toEqual([1, 2, 3, 4, 5]);
expect(getArrayOfPositives([0, 1, 2, 3, 4, 5])).toEqual([0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5]);
expect(getArrayOfPositives([])).toEqual([]);
});

test(`(3 pts) Testing removeFalsyValues`, () => {
expect(removeFalsyValues([0, false, "cat", NaN, true, ""])).toEqual(["cat", true]);
expect(removeFalsyValues([1, 2, 3, 4, 5, "false"])).toEqual([1, 2, 3, 4, 5, "false"]);
expect(removeFalsyValues([false, 0, NaN, "", undefined])).toEqual([]);
});
test(`(3 pts) Testing removeFalsyValues`, () => {
expect(removeFalsyValues([0, false, "cat", NaN, true, ""])).toEqual(["cat", true]);
expect(removeFalsyValues([1, 2, 3, 4, 5, "false"])).toEqual([1, 2, 3, 4, 5, "false"]);
expect(removeFalsyValues([false, 0, NaN, "", undefined])).toEqual([]);
});

test(`(3 pts) Testing getStringsLength`, () => {
expect(getStringsLength(["", "a", "bc", "def", "ghij"])).toEqual([0, 1, 2, 3, 4]);
expect(getStringsLength(["angular", "react", "ember"])).toEqual([7, 5, 5]);
});
test(`(3 pts) Testing getStringsLength`, () => {
expect(getStringsLength(["", "a", "bc", "def", "ghij"])).toEqual([0, 1, 2, 3, 4]);
expect(getStringsLength(["angular", "react", "ember"])).toEqual([7, 5, 5]);
});

test(`(3 pts) Testing getItemsSum`, () => {
expect(getItemsSum([])).toEqual(0);
expect(getItemsSum([1, 2, 3])).toEqual(6);
expect(getItemsSum([-1, 1, -1, 1])).toEqual(0);
expect(getItemsSum([1, 10, 100, 1000])).toEqual(1111);
test(`(3 pts) Testing getItemsSum`, () => {
expect(getItemsSum([])).toEqual(0);
expect(getItemsSum([1, 2, 3])).toEqual(6);
expect(getItemsSum([-1, 1, -1, 1])).toEqual(0);
expect(getItemsSum([1, 10, 100, 1000])).toEqual(1111);
});
});
Loading

1 comment on commit 56a3ad7

@vercel
Copy link

@vercel vercel bot commented on 56a3ad7 Apr 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.