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
4 changes: 2 additions & 2 deletions 1-exercises/B-array-literals/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
Declare some variables assigned to arrays of values
*/

let numbers = []; // add numbers from 1 to 10 into this array
let mentors; // Create an array with the names of the mentors: Daniel, Irina and Rares
let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; // add numbers from 1 to 10 into this array
let mentors = ["Daniel", "Irina", "Rares"]; // Create an array with the names of the mentors: Daniel, Irina and Rares

/*
DO NOT EDIT BELOW THIS LINE
Expand Down
4 changes: 2 additions & 2 deletions 1-exercises/C-array-get-set/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
*/

function first(arr) {
return; // complete this statement
return numbers=[0]; // complete this statement
}

function last(arr) {
return; // complete this statement
return names=[2]; // complete this statement
}

/*
Expand Down
9 changes: 8 additions & 1 deletion 1-exercises/E-while-loop-with-array/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ const BIRTHDAYS = [
];

function findFirstJulyBDay(birthdays) {
// TODO
let currentIndex = 0;

while(currentIndex < birthdays.length){
if (birthdays[currentIndex].includes("July")){
return birthdays[currentIndex];
}
currentIndex ++;
}
}

console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th"
10 changes: 9 additions & 1 deletion 2-mandatory/1-weather-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@
*/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks good 👍
One suggestion - it's a good idea to use let or const when declaring variables. This code will still work without it, but when you start working on larger programs - you could run into problems.

function getTemperatureReport(cities) {
// TODO
output=[];
for (city of cities) {
temperature = temperatureService(city);
string = `The temperature in ${city} is ${temperature} degrees`;
output.push (string);

}
return output;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment: Well done!
Consider: You could also use iterate variable as below.
function getTemperatureReport(cities) {
const temperatureReport = [];
for(let i = 0; i < cities.length; i++) {
const temperature = temperatureService(cities[i]);
temperatureReport.push(The temperature in ${cities[i]} is ${temperature} degrees);
}
return temperatureReport;
}


}


Expand Down
50 changes: 45 additions & 5 deletions 2-mandatory/2-financial-times.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
Implement the function below, which will return a new array containing only article titles which will fit.
*/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Almost perfect - but same comment as above about using let or const 😄
For an extra challenge, try re-writing the below function using the filter array method.

function potentialHeadlines(allArticleTitles) {
// TODO
allTitles = [];
for (headline of allArticleTitles){
if (headline.length <= 65) {
allTitles.push(headline)
}
}
return allTitles;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment: Same solution as mine

}

/*
Expand All @@ -14,24 +20,58 @@ function potentialHeadlines(allArticleTitles) {
(you can assume words will always be seperated by a space)
*/
function titleWithFewestWords(allArticleTitles) {
// TODO

let shortestLine;
let length_headline = 100000;

for (headline of allArticleTitles) {
let currentTitleWordCount = headline.split (" ").length;

if (currentTitleWordCount < length_headline) {
shortestLine = headline;
length_headline = currentTitleWordCount;
}
}

return shortestLine;

}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment: I see you use 100000; as a value. I assume it is a made up value.

Consider: Have a look at how you can use [i] It is not used in any of your coding.

Example:
function titleWithFewestWords(allArticleTitles) {
let shortestTitle = allArticleTitles[0];

for (let i = 1; i < allArticleTitles.length; i++) {
    let currentTitle = allArticleTitles[i];
    if (currentTitle.length < shortestTitle.length) {
        shortestTitle = currentTitle  
    }
}
return shortestTitle;

}




/*
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)
*/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Very nice solution!
I like that you've used a separate function to check if the string has a number. It makes the code very easy to read 👍

function hasNumber(myString) {
return /\d/.test(myString);
}

function headlinesWithNumbers(allArticleTitles) {
// TODO
let arrayWithNumbers = [];
for (headline of allArticleTitles) {
let includesNumber = hasNumber(headline)
if (includesNumber) {
arrayWithNumbers.push(headline)
}
}

return arrayWithNumbers;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment: I see you use parseInt. Nice. Different solution to mine

}

/*
/*
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
let totalCharacters = 0;
for (const headline of allArticleTitles){
totalCharacters = totalCharacters + headline.length;
}
return Math.round(totalCharacters / allArticleTitles.length);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment: Nice!



Expand Down
39 changes: 36 additions & 3 deletions 2-mandatory/3-stocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,18 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [
Functions can help with this!
*/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great job!
Now that you have something that works - maybe you could split some of the code into a separate function improve readability. For example, you could have a function which just calculates the average price given the stockPricesLastFiveDays array.

function getAveragePrices(closingPricesForAllStocks) {
// TODO
let arrayOfAveragePrices = [];

for (const stockPricesLastFiveDays of closingPricesForAllStocks) {
let sum = 0;
for (const stock of stockPricesLastFiveDays){
sum += stock;
}
const averagePrice = Math.round((sum / stockPricesLastFiveDays.length ) * 100 ) / 100

arrayOfAveragePrices.push(averagePrice)
}
return arrayOfAveragePrices;
}

/*
Expand All @@ -48,9 +59,20 @@ 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) {
// TODO
let newArrayOfDifference = [];
for (let oneSetOfPrices of closingPricesForAllStocks){
lengthOfArray = oneSetOfPrices.length;
finalPositionInArray = lengthOfArray - 1;

let firstPrice = oneSetOfPrices[0];
let lastPrice = oneSetOfPrices[finalPositionInArray];
let differencePrice = Math.round((lastPrice - firstPrice) * 100) / 100;
newArrayOfDifference.push(differencePrice);
}
return newArrayOfDifference;
}


/*
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
Expand All @@ -64,8 +86,19 @@ function getPriceChanges(closingPricesForAllStocks) {
The price should be shown with exactly 2 decimal places.
*/
function highestPriceDescriptions(closingPricesForAllStocks, stocks) {
// TODO
let highestPriceForEachStock = [];
let highestPrice = 0;
let stock = 0;
for (element of closingPricesForAllStocks) {
highestPrice = Math.max(...element).toFixed(2);
highestPriceForEachStock.push( `The highest price of ${stocks[stock].toUpperCase()} in the last 5 days was ${highestPrice}`);
stock++;
}
return highestPriceForEachStock;
}





/* ======= TESTS - DO NOT MODIFY ===== */
Expand Down