This repository was archived by the owner on Jan 14, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 279
London 9 - George Primentas - JavaScript Core 1 - Week 3 #191
Open
GeorgePrimentas
wants to merge
2
commits into
CodeYourFuture:main
Choose a base branch
from
GeorgePrimentas:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,19 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [ | |
| */ | ||
| function getAveragePrices(closingPricesForAllStocks) { | ||
| // TODO | ||
| let averageArray = [] | ||
| for (let average of closingPricesForAllStocks) { | ||
| averageArray.push(getAverage(average)); | ||
| } | ||
| return averageArray | ||
| } | ||
|
|
||
| function getAverage(pricesOfEachStock) { | ||
| let sum = 0; | ||
| for (let price of pricesOfEachStock) { | ||
| sum = sum + price | ||
| } | ||
| return Number((sum / 5).toFixed(2)); | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -49,8 +62,16 @@ function getAveragePrices(closingPricesForAllStocks) { | |
| */ | ||
| function getPriceChanges(closingPricesForAllStocks) { | ||
| // TODO | ||
| let differenceArray = [] | ||
| for (let difference of closingPricesForAllStocks) { | ||
| differenceArray.push(Number((difference[difference.length-1] - difference[0]).toFixed(2))); // Definitely this is supercomplicated | ||
| } | ||
| return differenceArray; | ||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
||
| /* | ||
| As part of a financial report, we want to see what the highest price was for each stock in the last 5 days. | ||
| Implement the below function, which | ||
|
|
@@ -65,6 +86,27 @@ function getPriceChanges(closingPricesForAllStocks) { | |
| */ | ||
| function highestPriceDescriptions(closingPricesForAllStocks, stocks) { | ||
| // TODO | ||
| let theHighestPrice = highestPrice(closingPricesForAllStocks); | ||
| console.log(theHighestPrice) | ||
| let report = []; | ||
| let i = 0; | ||
| for (let stock of stocks) { | ||
| report.push("The highest price of " + stock.toUpperCase() + " in the last 5 days was " + theHighestPrice[i]) | ||
| i++; | ||
| } | ||
| return report; | ||
|
|
||
| } | ||
|
|
||
| function highestPrice(closingPrices) { | ||
| highestPrices = []; | ||
| for (let price of closingPrices) { | ||
| highestPrices.push(/*Number*/((Math.max.apply(null, price)).toFixed(2))) // Found this solution here: https://stackoverflow.com/questions/1669190/find-the-min-max-element-of-an-array-in-javascript | ||
| // It works but I don't understand it - If I kept the Number method it would show the last higestPrice with one decimal after the point; not two... | ||
|
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. When you have Number and you're using toFixed(2) method on Number. You will have 2 decimal number after dot only if they are not including zero at the end. When you have String - you will have two decimalsafter dot in any case. But the number will be a String. So that's why it is better to leave the highest price as a String. Because in test we have a price "1101.30", not "1101.3". And we should only to show the price in sentence, we don't have any test which is checking if the price is a number. |
||
| // highestPrices.push(Math.max(price)) This didn't work | ||
| } | ||
| return highestPrices; | ||
| console.log(highestPrices) | ||
| } | ||
|
|
||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max Please write about finding max number in array. I found the easiest way for me to find max number in array using spread syntax.
const arr = [1, 2, 3];
const max = Math.max(...arr);