Skip to content

Oleksandr Starshynov week3 JavaScript #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .test-summary/TEST_SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Test Summary

**Mentors**: For more information on how to review homework assignments, please refer to the [Review Guide](https://github.com/HackYourFuture/mentors/blob/main/assignment-support/review-guide.md).

### 1-JavaScript - Week3

| Exercise | Passed | Failed | ESLint |
|----------------------------|--------|--------|--------|
| ex1-doubleEvenNumbers.test | 1 | - | ✓ |

Choose a reason for hiding this comment

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

Well done completing Week 3 assignment. Approved!!!

| ex2-mondaysWorth.test | 2 | - | ✓ |
| ex3-lemonAllergy.test | 3 | - | ✓ |
| ex4-observable | 3 | - | ✓ |
| ex5-wallet | 5 | - | ✓ |
22 changes: 3 additions & 19 deletions 1-JavaScript/Week3/assignment/ex1-doubleEvenNumbers.test.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,9 @@
/*------------------------------------------------------------------------------
Full description at: https://github.com/HackYourFuture/Assignments/tree/main/1-JavaScript/Week4#exercise-1-the-odd-ones-out

The `doubleEvenNumbers` function returns only the even numbers in the array
passed as the `numbers` parameter and doubles them.

Let's rewrite it (or _refactor_ it, as experienced developers would call it):

- Using the `map` and `filter` functions, rewrite the function body of
`doubleEvenNumbers`.
------------------------------------------------------------------------------*/
// ! Function to be tested
function doubleEvenNumbers(numbers) {
// TODO rewrite the function body using `map` and `filter`.
const newNumbers = [];
for (let i = 0; i < numbers.length; i++) {
if (numbers[i] % 2 === 0) {
newNumbers.push(numbers[i] * 2);
}
const evenNumbers = numbers.filter(num => num % 2 === 0);
const doubledNumbers = evenNumbers.map(num => num * 2);
return doubledNumbers;
}
return newNumbers;
}

// ! Unit test (using Jest)
describe('js-wk3-ex1-doubleEvenNumbers', () => {
Expand Down
9 changes: 7 additions & 2 deletions 1-JavaScript/Week3/assignment/ex2-mondaysWorth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@ const mondayTasks = [

const hourlyRate = 25;

function computeEarnings(/* TODO parameter(s) go here */) {
// TODO complete this function
function computeEarnings(tasks, hourlyRate) {
const totalEarnings = tasks
.map(task => task.duration / 60 * hourlyRate)
.reduce((sum, earnings) => sum + earnings, 0);
return `€${totalEarnings.toFixed(2)}`;
}

console.log(computeEarnings(mondayTasks, hourlyRate));

// ! Unit tests (using Jest)
describe('js-wk3-mondaysWorth', () => {
test('computeEarnings should take two parameters', () => {
Expand Down
34 changes: 8 additions & 26 deletions 1-JavaScript/Week3/assignment/ex3-lemonAllergy.test.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
/*------------------------------------------------------------------------------
Full description at: https://github.com/HackYourFuture/Assignments/tree/main/1-JavaScript/Week4#exercise-3-lemon-allergy

Your mom bought you a basket of fruit, because you're doing so well in
HackYourFuture. How sweet of her!

However, she forgot that you are allergic to lemons! Let's quickly dispose of
them before you get an attack.

Complete the function called `sanitizeFruitBasket`:

- It should take two parameters: an array of strings representing a fruit basket
to be sanitized and a string indicating the name of the fruit to be taken out.
- Use the `filter` array method to take out the unwanted fruit.
- Return a new array that contains the fruits without any lemons.
------------------------------------------------------------------------------*/
const fruitBasket = [
'apple',
'lemon',
Expand All @@ -25,26 +9,24 @@ const fruitBasket = [
];

// ! Function under test
function sanitizeFruitBasket(/* TODO parameter(s) go here */) {
// TODO complete this function
function sanitizeFruitBasket(basket, fruitAllergy) {
const newBasket = basket.filter((item) => item !== fruitAllergy);
return newBasket;
}

// ! Unit tests (using Jest)
describe('js-wk3-ex3-lemonAllergy', () => {
test('sanitizeFruitBasket should take two parameters', () => {
// TODO replace next line with your code
expect(false).toBe(true);
expect(sanitizeFruitBasket.length).toBe(2);
});

test('sanitizeFruitBasket should not modify the original `fruitBasket` array', () => {
// Save the original contents of the fruit basket
const originalFruitBasketContents = [...fruitBasket];
// TODO replace next line with your code
expect(false).toBe(true);
expect(originalFruitBasketContents.length).toBe(fruitBasket.length);
});

test('sanitizeFruitBasket should return a new array that does not include the unwanted `lemon`', () => {
// TODO replace next line with your code
expect(false).toBe(true);
const allergyArray = sanitizeFruitBasket(fruitBasket, 'lemon');
expect(allergyArray).not.toContain('lemon');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ export function createObservable() {
const subscribers = [];
return {
subscribe(subscriber) {
// TODO complete this function
subscribers.push(subscriber);
},
notify(message) {
// TODO complete this function
subscribers.forEach(subscriber => {
subscriber(message);
});
},
};
}
}
12 changes: 6 additions & 6 deletions 1-JavaScript/Week3/assignment/ex5-wallet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function createWallet(name, cash = 0) {
function transferInto(wallet, amount) {
console.log(
`Transferring ${eurosFormatter.format(amount)} from ${name} to ${
wallet.name
wallet.getName()
}`
);
const withdrawnAmount = withdraw(amount);
Expand Down Expand Up @@ -75,7 +75,7 @@ const quiz = {
b: 'cash, name',
c: 'amount, this, wallet'
},
answer: '?',
answer: 'b',
},
q2: {
question: 'What is in the Call Stack, from top to bottom?',
Expand All @@ -84,7 +84,7 @@ const quiz = {
b: 'anonymous, transferInto',
c: 'transferInto, anonymous'
},
answer: '?',
answer: 'c',
},
q3: {
question: 'What tooltip appears when hovering over the third debug button?',
Expand All @@ -93,7 +93,7 @@ const quiz = {
b: 'Step out of current function',
c: 'Step'
},
answer: '?',
answer: 'a',
},
q4: {
question: 'What is displayed in the console?',
Expand All @@ -102,7 +102,7 @@ const quiz = {
b: 'Transferring € 50,00 from Jack to undefined',
c: 'Transferring € 50,00 from Jack to Jane'
},
answer: '?',
answer: 'a',
},
q5: {
question: 'The owner of the wallet with insufficient funds is:',
Expand All @@ -111,6 +111,6 @@ const quiz = {
b: 'Joe',
c: 'Jane'
},
answer: '?',
answer: 'c',
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
*** Unit Test Error Report ***

PASS 1-JavaScript/Week3/assignment/ex1-doubleEvenNumbers.test.js
js-wk3-ex1-doubleEvenNumbers
✅ doubleEvenNumbers should take the even numbers and double them (3 ms)

Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 0.945 s, estimated 1 s
Ran all test suites matching /D:\\HYF\\HYF-Assignments-cohort52\\1-JavaScript\\Week3\\assignment\\ex1-doubleEvenNumbers.test.js/i.
No linting errors detected.
No spelling errors detected.
19 changes: 19 additions & 0 deletions 1-JavaScript/Week3/test-reports/ex2-mondaysWorth.test.report.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
*** Unit Test Error Report ***

console.log
€187.50

at Object.log (1-JavaScript/Week3/assignment/ex2-mondaysWorth.test.js:40:9)

PASS 1-JavaScript/Week3/assignment/ex2-mondaysWorth.test.js
js-wk3-mondaysWorth
✅ computeEarnings should take two parameters (3 ms)
✅ computeEarnings should compute the earnings as a formatted Euro amount (1 ms)

Test Suites: 1 passed, 1 total
Tests: 2 passed, 2 total
Snapshots: 0 total
Time: 0.768 s, estimated 1 s
Ran all test suites matching /D:\\HYF\\HYF-Assignments-cohort52\\1-JavaScript\\Week3\\assignment\\ex2-mondaysWorth.test.js/i.
No linting errors detected.
No spelling errors detected.
15 changes: 15 additions & 0 deletions 1-JavaScript/Week3/test-reports/ex3-lemonAllergy.test.report.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*** Unit Test Error Report ***

PASS 1-JavaScript/Week3/assignment/ex3-lemonAllergy.test.js
js-wk3-ex3-lemonAllergy
✅ sanitizeFruitBasket should take two parameters (3 ms)
✅ sanitizeFruitBasket should not modify the original `fruitBasket` array
✅ sanitizeFruitBasket should return a new array that does not include the unwanted `lemon` (1 ms)

Test Suites: 1 passed, 1 total
Tests: 3 passed, 3 total
Snapshots: 0 total
Time: 1.307 s
Ran all test suites matching /D:\\HYF\\HYF-Assignments-cohort52\\1-JavaScript\\Week3\\assignment\\ex3-lemonAllergy.test.js/i.
No linting errors detected.
No spelling errors detected.
15 changes: 15 additions & 0 deletions 1-JavaScript/Week3/test-reports/ex4-observable.report.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*** Unit Test Error Report ***

PASS 1-JavaScript/Week3/assignment/ex4-observable/ex4-observable.test.js
js-wk3-ex4-observable
✅ createObservable should exist and be a function (7 ms)
✅ createObservable should return an object with `subscribe` and a `notify` function properties (1 ms)
✅ observable should notify all subscribers of any notification (2 ms)

Test Suites: 1 passed, 1 total
Tests: 3 passed, 3 total
Snapshots: 0 total
Time: 0.866 s, estimated 1 s
Ran all test suites matching /D:\\HYF\\HYF-Assignments-cohort52\\1-JavaScript\\Week3\\assignment\\ex4-observable\\ex4-observable.test.js/i.
No linting errors detected.
No spelling errors detected.
17 changes: 17 additions & 0 deletions 1-JavaScript/Week3/test-reports/ex5-wallet.report.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
*** Unit Test Error Report ***

PASS .dist/1-JavaScript/Week3/unit-tests/ex5-wallet.test.js
js-wk3-ex5-wallet
✅ q1: At line 24, which variables are in the scope marked Closure? (2 ms)
✅ q2: What is in the Call Stack, from top to bottom? (1 ms)
✅ q3: What tooltip appears when hovering over the third debug button?
✅ q4: What is displayed in the console? (1 ms)
✅ q5: The owner of the wallet with insufficient funds is?

Test Suites: 1 passed, 1 total
Tests: 5 passed, 5 total
Snapshots: 0 total
Time: 0.717 s, estimated 1 s
Ran all test suites matching /D:\\HYF\\HYF-Assignments-cohort52\\.dist\\1-JavaScript\\Week3\\unit-tests\\ex5-wallet.test.js/i.
No linting errors detected.
No spelling errors detected.