-
-
Notifications
You must be signed in to change notification settings - Fork 279
London10_Anna-Hrychaniuk_JavaScript-Core-1-Coursework-Week3 #232
base: main
Are you sure you want to change the base?
Changes from all commits
7bfd43a
955a64a
74155fa
013a4ce
244c1d6
b47e554
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,25 @@ | ||
| { | ||
| "configurations": [ | ||
|
|
||
| { | ||
| "args": [ | ||
| "--extensionDevelopmentPath=${workspaceFolder}" | ||
| ], | ||
| "name": "Launch Extension", | ||
| "outFiles": [ | ||
| "${workspaceFolder}/out/**/*.js" | ||
| ], | ||
| "preLaunchTask": "npm", | ||
| "request": "launch", | ||
| "type": "extensionHost" | ||
| }, | ||
| { | ||
| "type": "node", | ||
| "name": "Run Current File", | ||
| "request": "launch", | ||
| "program": "${workspaceFolder}/2-mandatory/3-stocks.js", | ||
| "stopOnEntry": true | ||
|
|
||
| } | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,13 @@ | |
| Implement the function below, which will return a new array containing only article titles which will fit. | ||
| */ | ||
| function potentialHeadlines(allArticleTitles) { | ||
|
Contributor
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 one 😄 |
||
| // TODO | ||
| // let shortTitles = []; | ||
| // for (let item of allArticleTitles){ | ||
| // if (item.length <= 65) { | ||
| // shortTitles.push(item); | ||
| // } | ||
| // } | ||
| return allArticleTitles.filter(article => article.length <=65); | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -14,7 +20,17 @@ function potentialHeadlines(allArticleTitles) { | |
| (you can assume words will always be seperated by a space) | ||
| */ | ||
| function titleWithFewestWords(allArticleTitles) { | ||
| // TODO | ||
| let shortestHeadline; | ||
| let fewestNumber; | ||
| for (let item of allArticleTitles) { | ||
| let numberOfWords = item.split(' ').length; | ||
|
|
||
| if (fewestNumber === undefined || numberOfWords < fewestNumber) { | ||
| shortestHeadline = item; | ||
| fewestNumber = numberOfWords; | ||
| } | ||
| } | ||
| return shortestHeadline; | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -23,15 +39,30 @@ function titleWithFewestWords(allArticleTitles) { | |
| (Hint: remember that you can also loop through the characters of a string if you need to) | ||
| */ | ||
| function headlinesWithNumbers(allArticleTitles) { | ||
|
Contributor
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 and simple solution. |
||
| // TODO | ||
| let linesWithNumbers = []; | ||
| for (let item of allArticleTitles) { | ||
| if (/\d/.test(item)) { | ||
| linesWithNumbers.push(item); | ||
| } | ||
| } | ||
| return linesWithNumbers; | ||
| } | ||
|
|
||
| /* | ||
| 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. | ||
| */ | ||
| function averageNumberOfCharacters(allArticleTitles) { | ||
| // TODO | ||
| // number of characters in each article | ||
| // number of characters/number of articles (allArticleTitles.length) | ||
|
|
||
| let charactersAmount = 0; | ||
| for (let item of allArticleTitles) { | ||
| let charSum = item.length; | ||
| charactersAmount +=charSum; | ||
| } | ||
| let average = charactersAmount / allArticleTitles.length; | ||
| return Math.round(average); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,7 +34,18 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [ | |
| Functions can help with this! | ||
| */ | ||
| function getAveragePrices(closingPricesForAllStocks) { | ||
|
Contributor
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 looks good to me. |
||
| // TODO | ||
| let averagePrices = []; | ||
| for (let item of closingPricesForAllStocks) { | ||
| let sum=0; | ||
| let average = 0; | ||
| for (let i of item) { | ||
| sum +=i; | ||
| } | ||
| average = sum/item.length; | ||
| averagePrices.push(Number(average.toFixed(2))); | ||
| } | ||
|
|
||
| return averagePrices; | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -48,7 +59,13 @@ function getAveragePrices(closingPricesForAllStocks) { | |
| The price change value should be rounded to 2 decimal places, and should be a number (not a string) | ||
| */ | ||
| function getPriceChanges(closingPricesForAllStocks) { | ||
|
Contributor
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 looks good as well. |
||
| // TODO | ||
| let priceChanges = []; | ||
| for (let item of closingPricesForAllStocks) { | ||
| let changed = item[item.length-1] - item[0]; | ||
| priceChanges.push(Number(changed.toFixed(2))); | ||
| } | ||
|
|
||
| return priceChanges; | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -64,7 +81,24 @@ function getPriceChanges(closingPricesForAllStocks) { | |
| The price should be shown with exactly 2 decimal places. | ||
| */ | ||
| function highestPriceDescriptions(closingPricesForAllStocks, stocks) { | ||
|
Contributor
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. Good work on this one 👍 |
||
| // TODO | ||
|
|
||
| let priceDescrip = []; | ||
| let biggestPrice = 0; | ||
| let biggestPriceArray = []; | ||
| for (let item of closingPricesForAllStocks) { | ||
| let biggestPrice = 0; | ||
| for (let i of item) { | ||
| if (i > biggestPrice) { | ||
| biggestPrice = i; | ||
| } | ||
| } | ||
| biggestPriceArray.push(biggestPrice.toFixed(2)); | ||
| } | ||
| for (let i=0; i<stocks.length; i++) | ||
| { | ||
| priceDescrip.push("The highest price of " + stocks[i].toUpperCase() + " in the last 5 days was " + biggestPriceArray[i]); | ||
| } | ||
| return priceDescrip; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,15 @@ | |
| */ | ||
|
|
||
| // `getAllFrequencies` goes here | ||
| function getAllFrequencies() { | ||
| const allFrequencies = []; | ||
| let i = 87; | ||
| while (i <=108) { | ||
| allFrequencies.push(i); | ||
| i++; | ||
| } | ||
| return allFrequencies | ||
| } | ||
|
|
||
| /** | ||
| * Next, let's write a function that gives us only the frequencies that are radio stations. | ||
|
|
@@ -25,6 +34,16 @@ | |
| * - Return only the frequencies that are radio stations. | ||
| */ | ||
| // `getStations` goes here | ||
| function getStations () { | ||
|
Contributor
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 solution 👍
Author
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. done :) |
||
| let allFrequencies = getAllFrequencies(); | ||
| // const stations = []; | ||
| // for (let item of allFrequencies){ | ||
| // if (isRadioStation(item)) { | ||
| // stations.push(item); | ||
| // } | ||
| // } | ||
| return allFrequencies.filter(isRadioStation); | ||
| } | ||
|
|
||
| /* | ||
| * ======= 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.
Good job 👍