-
-
Notifications
You must be signed in to change notification settings - Fork 283
London10-Afsha-Hossain-JS-Core1-Coursework-Week3 #257
base: main
Are you sure you want to change the base?
Changes from all commits
017ff7b
a5138d4
de3fc86
e32cf5f
0c6af51
c1d359d
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 |
---|---|---|
|
@@ -16,8 +16,15 @@ const BIRTHDAYS = [ | |
"November 15th" | ||
]; | ||
|
||
function findFirstJulyBDay(birthdays) { | ||
function findFirstJulyBDay(BIRTHDAYS) { | ||
// TODO | ||
let i = 0; | ||
while (i < BIRTHDAYS.length) { | ||
if (BIRTHDAYS[i].startsWith("July")) { | ||
return BIRTHDAYS[i]; | ||
} | ||
i++; | ||
} | ||
} | ||
|
||
console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th" | ||
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. Nice work, consice and good. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,19 @@ | |
- Hint: you can call the temperatureService function from your function | ||
*/ | ||
|
||
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. Looks perfect 👍 |
||
// 1. Create a new empty array | ||
// 2. Loop through the cities, and for each city: | ||
// a. Create a new string for the weather report of that city | ||
// b. Add that new string into the array | ||
// 3. Return the array | ||
|
||
function getTemperatureReport(cities) { | ||
let arr = []; | ||
for (let city of cities) { | ||
let weatherReport = `The temperature in ${city} is ${temperatureService(city)} degrees`; | ||
arr.push(weatherReport); | ||
} | ||
return arr; | ||
// TODO | ||
} | ||
|
||
|
@@ -32,6 +44,11 @@ function temperatureService(city) { | |
return temparatureMap.get(city); | ||
} | ||
|
||
test("should return array of same length as argument", () => { | ||
let usersCities = ["London", "Paris", "São Paulo"]; | ||
expect(getTemperatureReport(usersCities).length).toEqual(3); | ||
}); | ||
|
||
test("should return a temperature report for the user's cities", () => { | ||
let usersCities = [ | ||
"London", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,13 @@ | |
Implement the function below, which will return a new array containing only article titles which will fit. | ||
*/ | ||
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 look good! |
||
function potentialHeadlines(allArticleTitles) { | ||
let newArray = []; | ||
for (let item of allArticleTitles) { | ||
if (item.length <= 65) { | ||
newArray.push(item); | ||
} | ||
} | ||
return newArray; | ||
// TODO | ||
} | ||
|
||
|
@@ -13,25 +20,72 @@ function potentialHeadlines(allArticleTitles) { | |
Implement the function below, which returns the title with the fewest words. | ||
(you can assume words will always be seperated by a space) | ||
*/ | ||
// ["The", "three", "questions", "that", "dominate", "investment"] | ||
// fewestNumberOfWords = articleSplitter.length; | ||
|
||
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 is a very good attempt 👍 One small improvement:
|
||
function titleWithFewestWords(allArticleTitles) { | ||
let shortestHeadline; | ||
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 could declare 'shortestHeadline' with const keyword instead let 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. I think |
||
let fewestNumberOfWords = 1000; | ||
|
||
for (let headline of allArticleTitles) { | ||
let splitArticleTitle = (headline.split(" ")); | ||
if (splitArticleTitle.length < fewestNumberOfWords) { | ||
fewestNumberOfWords = splitArticleTitle.length; | ||
shortestHeadline = headline; | ||
} | ||
} | ||
return shortestHeadline; | ||
// TODO | ||
// loop through the headlines | ||
// find number words in the headline | ||
// find number of words in title | ||
// compare the number with | ||
} | ||
|
||
|
||
/* | ||
The editor of the FT has realised that headlines which have numbers in them get more clicks! | ||
Implement the function below to return a new array containing all the headlines which contain a number. | ||
(Hint: remember that you can also loop through the characters of a string if you need to) | ||
*/ | ||
|
||
// 1. We are getting array of string. We need to find if the string includes numbers. | ||
// 2. Once we find a number, we will put the string to the new array. | ||
// 3. We are going to return the new array. New array is string with numbers. | ||
|
||
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. Very nice 👍 |
||
function headlinesWithNumbers(allArticleTitles) { | ||
let newArrayWithNum = []; | ||
for (const title of allArticleTitles) { | ||
if (/\d/.test(title)) { | ||
newArrayWithNum.push(title); | ||
} | ||
} | ||
|
||
return newArrayWithNum; | ||
// TODO | ||
} | ||
|
||
// for (character of title) { | ||
// if (character.includes(Number)) { | ||
// newArrayWithNum.push(title) | ||
// } | ||
|
||
/* | ||
The Financial Times wants to understand what the average number of characters in an article title is. | ||
Implement the function below to return this number - rounded to the nearest integer. | ||
*/ | ||
// 1. We find total characters | ||
// 2. We need to find the number of Article titles. | ||
// 3. We divide (total character) by (number of article titles). | ||
// 4. Round it up | ||
|
||
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. Looks very good! |
||
function averageNumberOfCharacters(allArticleTitles) { | ||
// TODO | ||
let totalCharacter = 0; | ||
for (let item of allArticleTitles) { | ||
totalCharacter = totalCharacter + item.length; | ||
} | ||
return Math.round(totalCharacter / allArticleTitles.length); | ||
} | ||
|
||
|
||
|
@@ -50,6 +104,7 @@ const ARTICLE_TITLES = [ | |
"Brussels urges Chile's incoming president to endorse EU trade deal", | ||
]; | ||
|
||
|
||
/* ======= TESTS - DO NOT MODIFY ===== */ | ||
|
||
test("should only return potential headlines", () => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,8 +33,24 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [ | |
Solve the smaller problems, and then build those solutions back up to solve the larger problem. | ||
Functions can help with this! | ||
*/ | ||
|
||
// 1. Find the total price of each company stocks in the last 5 days | ||
// 2. Divide the total price by the number of days i.e. 5 | ||
|
||
|
||
|
||
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. Very good variable names 😄 |
||
function getAveragePrices(closingPricesForAllStocks) { | ||
// TODO | ||
let arrayOfAverageValues = []; | ||
for (let closingPriceEachCompany of closingPricesForAllStocks) { | ||
let sumOfClosingPriceEachCompany = 0; | ||
for (i = 0; i < closingPriceEachCompany.length; i++) { | ||
sumOfClosingPriceEachCompany = sumOfClosingPriceEachCompany + closingPriceEachCompany[i]; | ||
averagePriceEachCompany = (sumOfClosingPriceEachCompany / closingPriceEachCompany.length).toFixed(2); | ||
} | ||
averagePricesNumberType = parseFloat(averagePriceEachCompany); | ||
arrayOfAverageValues.push(averagePricesNumberType); | ||
} | ||
return arrayOfAverageValues; | ||
} | ||
|
||
/* | ||
|
@@ -47,8 +63,18 @@ function getAveragePrices(closingPricesForAllStocks) { | |
(Apple's price on the 5th day) - (Apple's price on the 1st day) = 172.99 - 179.19 = -6.2 | ||
The price change value should be rounded to 2 decimal places, and should be a number (not a string) | ||
*/ | ||
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. Nice! |
||
|
||
// 1. AAPL (apple) price difference last day - first day = -6.2 | ||
// | ||
|
||
function getPriceChanges(closingPricesForAllStocks) { | ||
// TODO | ||
let newPriceChangeArray = []; | ||
for (let oneSetOfPrices of closingPricesForAllStocks) { | ||
let priceChange = (oneSetOfPrices[(oneSetOfPrices.length - 1)] - oneSetOfPrices[0]).toFixed(2); //converted to 2 decimal places but it is also converted to string in the process | ||
let priceChangeValues = parseFloat(priceChange); // removing the string values to numbers | ||
newPriceChangeArray.push(priceChangeValues); | ||
} | ||
return newPriceChangeArray; | ||
} | ||
|
||
/* | ||
|
@@ -63,9 +89,41 @@ function getPriceChanges(closingPricesForAllStocks) { | |
The stock ticker should be capitalised. | ||
The price should be shown with exactly 2 decimal places. | ||
*/ | ||
function highestPriceDescriptions(closingPricesForAllStocks, stocks) { | ||
// TODO | ||
} | ||
|
||
// for (i = 0; i < closingPricesForAllStocks.length; i++) { | ||
// let highestPrice = 0;const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [ | ||
[179.19, 180.33, 176.28, 175.64, 172.99], // AAPL | ||
[340.69, 342.45, 334.69, 333.20, 327.29], // MSFT | ||
[3384.44, 3393.39, 3421.37, 3420.74, 3408.34], // AMZN | ||
[2951.88, 2958.13, 2938.33, 2928.30, 2869.45], // GOOGL | ||
[1101.30, 1093.94, 1067.00, 1008.87, 938.53] // TSLA | ||
|
||
// for (let companyPriceArray of closingPricesForAllStocks) { | ||
// if (companyPriceArray[i] > highestPrice) { | ||
// highestPrice = companyPriceArray[i]; | ||
// } | ||
// } | ||
// arrayWithHighestValue.push(highestPrice); | ||
|
||
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 was a tough one! |
||
function highestPriceDescriptions(closingPricesForAllStocks, stocks) { | ||
let highestCompanyStockPrices = []; | ||
let namesOfCompanies = []; | ||
let highestPrice = 0; | ||
for (i = 0; i < closingPricesForAllStocks.length; i++) { | ||
for (let closingPricePerDay of closingPricesForAllStocks[i]) { | ||
if (closingPricePerDay > highestPrice) { | ||
highestPrice = closingPricePerDay; | ||
} | ||
} | ||
let upperStock = stocks[i].toUpperCase(); | ||
highestCompanyStockPrices.push( | ||
`The highest price of ${upperStock} in the last 5 days was ${highestPrice.toFixed(2)}`); | ||
highestPrice = 0; | ||
} | ||
return highestCompanyStockPrices; | ||
// return `The highest price of ${stocks} in the last 5 days was ${arrayWithHighestValue[i]}`; | ||
} | ||
|
||
|
||
|
||
/* ======= TESTS - DO NOT MODIFY ===== */ | ||
|
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.
Nice explanation.