Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.
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
5 changes: 5 additions & 0 deletions 2-mandatory/1-weather-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
*/

function getTemperatureReport(cities) {
const arrayOfString = [];
for (let city of cities) {
arrayOfString.push(`The temperature in ${city} is ${temperatureService(city)} degrees`)
}
return arrayOfString;
Comment on lines +15 to +19

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👏

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I like how you have simplified your code Melese. I found it easier to understand.

// TODO
}

Expand Down
33 changes: 33 additions & 0 deletions 2-mandatory/2-financial-times.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
*/
function potentialHeadlines(allArticleTitles) {
// TODO
const newArray = [];
for (let articleTitle of allArticleTitles){
if (articleTitle.length <= 65){
newArray.push(articleTitle)
}
}
return newArray;
Comment on lines +9 to +15

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good! Although it's good to try and make variable names reflect what they are doing. For example here, a better name than newArray would have been, potentialHeadlines or similar

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is another good function Melese. Easy for someone else to follow.



}

/*
Expand All @@ -15,6 +24,16 @@ function potentialHeadlines(allArticleTitles) {
*/
function titleWithFewestWords(allArticleTitles) {
// TODO
const title = [];
let titleWithFewestWord = allArticleTitles[0].length;
for (let fewWord of allArticleTitles){
if (fewWord.split(' ').length < titleWithFewestWord){
titleWithFewestWord = fewWord.split(' ').length
title.push(fewWord)
}else{
titleWithFewestWord = titleWithFewestWord;
Comment on lines +33 to +34

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I don't think we need this else statement here as it's not doing anything. titleWithFewestWord already equals titleWithFewestWord. We can just stick with the if statement only

}
}return title[title.length-1];
}

/*
Expand All @@ -24,6 +43,15 @@ function titleWithFewestWords(allArticleTitles) {
*/
function headlinesWithNumbers(allArticleTitles) {
// TODO
const headlinesWithNumber =[];
for (let article of allArticleTitles){
for (let char of article){
if(char.match(/[0123456789]/g)){
headlinesWithNumber.push(article);break;
}
}
}return headlinesWithNumber;

Comment on lines +46 to +54

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice!

}

/*
Expand All @@ -32,6 +60,11 @@ function headlinesWithNumbers(allArticleTitles) {
*/
function averageNumberOfCharacters(allArticleTitles) {
// TODO
let averageNumberOfCharacter = 0;
for (let articleTitle of allArticleTitles){
averageNumberOfCharacter = averageNumberOfCharacter + articleTitle.length
}
return Math.round((averageNumberOfCharacter/allArticleTitles.length).toFixed(0))
}
Comment on lines +63 to 68

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👏



Expand Down
20 changes: 19 additions & 1 deletion 2-mandatory/3-stocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [
*/
function getAveragePrices(closingPricesForAllStocks) {
// TODO
}
const averagePrices = [];

for (let closingPriceForStock of closingPricesForAllStocks){
averagePrices.push(Number(((closingPriceForStock.reduce((a,b) => a + b, 0))/(closingPriceForStock.length)).toFixed(2)))
}
return averagePrices;

}

Comment on lines +38 to +46

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice use of reduce 👌


/*
We also want to see what the change in price is from the first day to the last day for each stock.
Expand All @@ -49,6 +57,11 @@ function getAveragePrices(closingPricesForAllStocks) {
*/
function getPriceChanges(closingPricesForAllStocks) {
// TODO
const priceChanges = [];
for (let closingPriceForStock of closingPricesForAllStocks){
priceChanges.push(Number((closingPriceForStock[closingPriceForStock.length-1]-closingPriceForStock[0]).toFixed(2)))
}
return priceChanges;
}

/*
Expand All @@ -64,7 +77,12 @@ function getPriceChanges(closingPricesForAllStocks) {
The price should be shown with exactly 2 decimal places.
*/
function highestPriceDescriptions(closingPricesForAllStocks, stocks) {

// TODO
const priceDescription = [];
for (let i = 0; i < closingPricesForAllStocks.length; i++){
priceDescription.push(`The highest price of ${stocks[i].toUpperCase()} in the last 5 days was ${(((closingPricesForAllStocks[i]).sort(function(a,b){return a - b})[closingPricesForAllStocks[i].length-1]).toFixed(2))}`) }
return priceDescription;
Comment on lines +82 to +85

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is great. The only suggestion I would make is to format your code so that it's easier to read. I think we are going to talk about this in class tomorrow :)

}


Expand Down