Skip to content

all exercises #56

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 8 commits 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
@@ -1,5 +1,5 @@
'use strict';

let name = undefined;
let name = 'Vitaliy Korolyk';

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

const year = undefined;
const year = 1995;

module.exports = { year };
3 changes: 1 addition & 2 deletions Exercises/3-hello.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';

const hello = null;

const hello = name => console.log(`Hello ${name}`);
module.exports = { hello };
11 changes: 11 additions & 0 deletions Exercises/4-range copy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

const range = (start, end) => {
const arr = [];
for (let i = 0; i <= end - start; i++) {
arr[i] = start + i;
}
return arr;
};
range(15, 30);
module.exports = { range };
10 changes: 8 additions & 2 deletions Exercises/4-range.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
'use strict';

const range = null;

const range = (start, end) => {
const arr = [];
for (let i = 0; i <= end - start; i++) {
arr[i] = start + i;
}
return arr;
};
range(15, 30);
module.exports = { range };
11 changes: 10 additions & 1 deletion Exercises/5-range-odd.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
'use strict';

const rangeOdd = null;
const rangeOdd = (start, end) => {
const arr = [];
for (let i = start; i <= end; i++) {
if (i % 2 !== 0) {
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
@@ -1,11 +1,22 @@
'use strict';

const square = null;
const square = x => x * x;

const cube = null;
const cube = x => x ** 3;

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

const calculate = null;
const arr = [];

const calculate = () => {
for (let i = 0; i <= 9; i++) {
const s = square(i);
const c = cube(i);
arr[i] = average(s, c);
}
return arr;
};

calculate(3);

module.exports = { square, cube, average, calculate };
9 changes: 7 additions & 2 deletions Exercises/7-objects.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
'use strict';

const fn = null;

const fn = () => {
const obj1 = { name: 'Vitalik' };
let obj2 = { name: 'Oleg' };
obj1.name = 'Oleg';
obj2.name = 'Vitalik';
obj2 = { name: 'Serge' };
};
module.exports = { fn };
10 changes: 8 additions & 2 deletions Exercises/8-create.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
'use strict';

const createUser = null;

const createUser = (name, city) => {
const obj = {
name,
city,
};
return obj;
};
createUser('Mark', 'Brody');
module.exports = { createUser };
12 changes: 9 additions & 3 deletions Exercises/9-array.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
'use strict';

const phonebook = null;

const findPhoneByName = null;
const phonebook = [
{ name: 'Vitalik', phone: '1234' },
{ name: 'Oleg', phone: '4321' },
];

const findPhoneByName = name => {
for (const x of phonebook) {
if (x.name === name) return x.phone;
}
};
module.exports = { phonebook, findPhoneByName };
8 changes: 6 additions & 2 deletions Exercises/a-hash.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
'use strict';

const phonebook = null;
const phonebook = {
Vitalik: 1234,
Oleg: 4321,
};

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

module.exports = { phonebook, findPhoneByName };