Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.

London 9 - George Primentas - JavaScript Core 1 - Week 3 - #191

Open
GeorgePrimentas wants to merge 2 commits into
CodeYourFuture:mainfrom
GeorgePrimentas:main
Open

London 9 - George Primentas - JavaScript Core 1 - Week 3#191
GeorgePrimentas wants to merge 2 commits into
CodeYourFuture:mainfrom
GeorgePrimentas:main

Conversation

@GeorgePrimentas

Copy link
Copy Markdown

Exercises & Mandatory exercises completed

Comment thread 2-mandatory/4-stocks.js
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

Copy link
Copy Markdown

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);

Comment thread 2-mandatory/4-stocks.js
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...

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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.
Examples of numbers:
10.563 => 10.56
10.100 => 10.1

When you have String - you will have two decimalsafter dot in any case. But the number will be a String.
"10.563" => "10.56"
"10.100" => "10.10"

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.

@VitalinaKuzmenko VitalinaKuzmenko left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! I love you solutions! I left some comments for you! Let me know if you need anything!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants