-
Notifications
You must be signed in to change notification settings - Fork 2
Домашка 5 #4
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
base: lesson-5
Are you sure you want to change the base?
Домашка 5 #4
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 |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /* const startDateStr = '02 Aug 1985'; | ||
| const endDateStr = '03 Aug 1985'; */ | ||
|
|
||
| const startDateStr = '31 Jan 2022'; | ||
| const endDateStr = '03 Feb 2021'; | ||
| function dateDiff(startDateStr = '1 Jan 2022', endDateStr = '1 Jan 2023', unit = 'seconds') { | ||
| const startDate = new Date(startDateStr); | ||
| const endDate = new Date(endDateStr); | ||
| const result = Math.abs(endDate - startDate); | ||
| const unitDivisor = { | ||
| 'seconds': result / 1000, | ||
| 'minutes': result / 60000, | ||
| 'hours': result / (1000 * 60 * 60), | ||
| 'days': result / (1000 * 60 * 60 * 24) | ||
|
|
||
|
|
||
|
|
||
| } | ||
|
|
||
| // switch (unit) { | ||
| // case 'seconds' : | ||
| // result = result / 1000; | ||
| // break; | ||
| // case "minutes" : | ||
| // result = result / 60000; | ||
| // break; | ||
| // case "hours" : | ||
| // result = result / (1000 * 60 * 60); | ||
| // break; | ||
| // case "days" : | ||
| // result = result / (1000 * 60 * 60 * 24); | ||
| // break; | ||
| // } | ||
|
Comment on lines
+20
to
+33
Owner
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. remove comment |
||
| console.log(unitDivisor[unit]); | ||
| } | ||
|
Owner
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. what are you returning in this function? |
||
|
|
||
| dateDiff(endDateStr, startDateStr, 'days'); | ||
|
|
||
| console.log(result); | ||
|
Owner
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.
Owner
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. Fix an error |
||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| function optimizer(data) { | ||
| const result = {}; | ||
| for (const [key, value] of Object.entries(data)) { | ||
| result[key.toLowerCase()] = parseFloat(value).toFixed(2); | ||
|
|
||
| } | ||
|
|
||
| return result; | ||
|
Comment on lines
+2
to
+8
Owner
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. Let's use the |
||
| }; | ||
|
|
||
| const priceData = { | ||
| Apples: '23.4', | ||
| BANANAS: '48', | ||
| oRAngGEs: '48.7584', | ||
| }; | ||
|
|
||
| let updatedPriceData = optimizer(priceData); | ||
| console.log(updatedPriceData) // {apples: '23.40', bananas: '48.00', oranges: '48.76'} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| function recursiveOddSumTo(number) { | ||
| if (number == 1) | ||
| return 1; | ||
|
Owner
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. use the |
||
| if (number % 2 == 1) | ||
| return (recursiveOddSumTo(number - 1) + number); | ||
|
Owner
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. move the main logic as a default return of the function |
||
|
|
||
| return (recursiveOddSumTo(number - 1)) | ||
| }; | ||
| console.log(recursiveOddSumTo(1)) // 1 | ||
| console.log(recursiveOddSumTo(10)) // 25 | ||
|
|
||
|
|
||
| function iterativeOddSumTo(number) { | ||
| let sum = 0; | ||
|
|
||
| for (i = 1; i <= number; i += 2) { | ||
| sum = sum + i; | ||
| } | ||
|
|
||
| return (sum); | ||
| } | ||
|
|
||
| console.log(iterativeOddSumTo(1)) // 1 | ||
| console.log(iterativeOddSumTo(10)) // 25 | ||

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 need these variables?