Skip to content

Pull request #90

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 1 commit into
base: master
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
2 changes: 1 addition & 1 deletion Exercises/1-let.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

// Define variable to store your name as a string

let name = undefined;
let name = 'Roman';

module.exports = { name };
2 changes: 1 addition & 1 deletion Exercises/2-const.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

// Define constant to store your birth year as a number

const year = undefined;
const year = 2006;

module.exports = { year };
4 changes: 3 additions & 1 deletion Exercises/3-hello.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

// Prepare function to print greeting with single argument

const hello = null;
const hello = (name) => {
console.log(`Hello, ${name}`);
};

module.exports = { hello };
10 changes: 9 additions & 1 deletion Exercises/4-range.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
// Implement function `range(start: number, end: number): array` returning
// array with all numbers from the range [15, 30] including endpoints

const range = null;
const range = (start, number) => {
const arr = [];

for (let i = start; i <= number; i++) {
arr.push(i);
}

return arr;
};

module.exports = { range };
12 changes: 11 additions & 1 deletion Exercises/5-range-odd.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
// Implement function `rangeOdd(start: number, end: number)` returning
// array with all odd numbers from the range [15, 30] including endpoints

const rangeOdd = null;
const isOdd = (a) => a % 2;

const rangeOdd = (start, end) => {
const arr = [];

for (let i = start; i <= end; i++) {
if (isOdd(i)) arr.push(i);
}

return arr;
};

module.exports = { rangeOdd };
19 changes: 15 additions & 4 deletions Exercises/6-calculate.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,23 @@
Call functions `square` and `cube` in loop, then pass their
results to function `average`. Print what `average` returns. */

const square = null;

const cube = null;
const square = (x) => x * x;

const average = null;
const cube = (x) => x ** 3;

const calculate = null;
const average = (a, b) => (a + b) / 2;

function calculate() {
const arr = [];

for (let i = 0; i <= 9; i++) {
const result = average(square(i), cube(i));
// console.log(result);
arr.push(result);
}

return arr;
}

module.exports = { square, cube, average, calculate };
13 changes: 12 additions & 1 deletion Exercises/7-objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@
- Try to assign other object to both identifiers.
- Explain script behaviour. */

const fn = null;
const fn = function() {
// Init objects
const obj1 = { name: 'Linus', };
let obj2 = { name: 'Satochi' };

// Just change value of field `name`
obj1.name = 'Richard';
obj2.name = 'Vitalik';

// Obj1 is a variable we can change data in it
obj2 = { name: 'Lennart' };
};

module.exports = { fn };
2 changes: 1 addition & 1 deletion Exercises/8-create.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
Example: `createUser('Marcus Aurelius', 'Roma')`
will return object `{ name: 'Marcus Aurelius', city: 'Roma' }` */

const createUser = null;
const createUser = (name, city) => ({ name, city });

module.exports = { createUser };
12 changes: 10 additions & 2 deletions Exercises/9-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@ Object example: `{ name: 'Marcus Aurelius', phone: '+380445554433' }`.
`findPhoneByName(name: string): string`. Returning phone from that object
where field `name` equals argument `name`. Use `for` loop for this search. */

const phonebook = null;
const phonebook = [
{ name: 'Linus Torvalds', phone: '+38056323498' },
{ name: 'Richard Stallman', phone: '+3808384834' },
{ name: 'Eugen Rochko', phone: '+380734190748' },
];

const findPhoneByName = null;
const findPhoneByName = (name) => {
for (const record of phonebook) {
if (record.name === name) return record;
}
};

module.exports = { phonebook, findPhoneByName };
8 changes: 6 additions & 2 deletions Exercises/a-hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ contains `phone`.
`findPhoneByName(name: string): string`. Returning phone from hash/object.
Use `hash[key]` to find needed phone. */

const phonebook = null;
const phonebook = {
linus: '+38056323498',
richard: '+3808384834',
eugen: '+380734190748',
};

const findPhoneByName = null;
const findPhoneByName = (name) => phonebook[name];

module.exports = { phonebook, findPhoneByName };