-
-
Notifications
You must be signed in to change notification settings - Fork 145
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
lab tasks 1, 2, 3, 4, 5, 6, 7, 8, 9, a #52
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
'use strict'; | ||
// | ||
let name = 'Don Kihot'; | ||
// | ||
module.exports = { name }; | ||
|
||
let name = undefined; | ||
|
||
module.exports = { name }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
'use strict'; | ||
|
||
const year = undefined; | ||
const year = 1917; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
module.exports = { year }; |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,5 +1,5 @@ | ||||||||||
'use strict'; | ||||||||||
|
||||||||||
const hello = null; | ||||||||||
const hello = name => console.log(`Hello, ${name}!`); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
We use single line functions when outer function need to return value of internal call. |
||||||||||
|
||||||||||
module.exports = { hello }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,18 @@ | ||
'use strict'; | ||
|
||
const range = null; | ||
|
||
const range = (start, end) => { | ||
const arr = []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You may allocate array with final length. See solution: https://github.com/HowProgrammingWorks/Reusable/blob/master/Solutions/4-range.js |
||
const length = end - start; | ||
|
||
for (let i = 0; i <= length; i++) { | ||
arr[i] = start; | ||
start++; | ||
} | ||
|
||
return arr; | ||
}; | ||
|
||
|
||
|
||
module.exports = { range }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,16 @@ | ||
'use strict'; | ||
|
||
const rangeOdd = null; | ||
const rangeOdd = (begin, end) => { | ||
const len = Math.ceil((end - begin) / 2); | ||
if (len < 0) return []; | ||
const array = new Array(len); | ||
let i = 0; | ||
for (let n = begin; n <= end; n++) { | ||
if (n % 2 !== 0) array[i++] = n; | ||
} | ||
return array; | ||
}; | ||
|
||
|
||
module.exports = { rangeOdd }; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,19 @@ | ||
'use strict'; | ||
|
||
const square = null; | ||
const square = n => n * n; | ||
|
||
const cube = null; | ||
const cube = n => n ** 3; | ||
|
||
const average = null; | ||
const average = (a, b) => (a + b) / 2; | ||
|
||
const calculate = () => { | ||
const arr = []; | ||
for (let i = 0; i <= 9; i++) { | ||
const calc = average(square(i), cube(i)); | ||
arr.push(calc); | ||
} | ||
return arr; | ||
}; | ||
|
||
const calculate = null; | ||
|
||
module.exports = { square, cube, average, calculate }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
'use strict'; | ||
|
||
const fn = null; | ||
const fn = () => { | ||
const name1 = { name: 'John' }; | ||
let name2 = { name: 'John' }; | ||
|
||
name1.name = 'Dou'; | ||
name2.name = 'Dou'; | ||
|
||
name2 = { name: 'John Dou' }; | ||
}; | ||
|
||
|
||
|
||
module.exports = { fn }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
'use strict'; | ||
|
||
const createUser = null; | ||
const createUser = (name, city) => ({ name, city }); | ||
|
||
console.log(createUser('John Dou', 'Rome')); | ||
|
||
|
||
module.exports = { createUser }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
'use strict'; | ||
|
||
const phonebook = null; | ||
const phonebook = [ | ||
{ name: 'Marcus Aurelius', phone: '+380445554-433' }, | ||
{ name: 'Mao Zedong', phone: '+380445554-722' }, | ||
{ name: 'Rene Descartes', phone: '+380445554-988' }, | ||
]; | ||
|
||
const findPhoneByName = null; | ||
const findPhoneByName = name => { | ||
for (const number of phonebook) number.name === name ? number.phone : null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will return undefined. |
||
}; | ||
|
||
module.exports = { phonebook, findPhoneByName }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
'use strict'; | ||
|
||
const phonebook = null; | ||
const phonebook = { | ||
MarcusAurelius: { phone: '+380445554-433' }, | ||
MaoZedong: { phone: '+380445554-722' }, | ||
ReneDescartes: { phone: '+380445554-988' }, | ||
}; | ||
|
||
const findPhoneByName = null; | ||
const findPhoneByName = name => phonebook[name]; | ||
|
||
module.exports = { phonebook, findPhoneByName }; |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you committing changes to readme?