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
File renamed without changes.
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
6 changes: 4 additions & 2 deletions 1-exercises/C-array-get-set/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
*/

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

function last(arr) {
return; // complete this statement
return arr[arr.length-1];
}



/*
DO NOT EDIT BELOW THIS LINE
--------------------------- */
Expand Down
3 changes: 3 additions & 0 deletions 1-exercises/C-array-get-set/exercises2.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

let numbers = [1, 2, 3]; // Don't change this array literal declaration

numbers.pushed = [4];
numbers [0] = (1);

/*
DO NOT EDIT BELOW THIS LINE
--------------------------- */
Expand Down
6 changes: 6 additions & 0 deletions 1-exercises/D-for-loop/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ const AGES = [
];

// TODO - Write for loop code here
for (let i = 0; i < WRITERS.length; i++) {
console.log (`${WRITERS[i]} is ${WRITERS[i]} years old.`)
return getTemperatureReport;

}


/*
The output should look something like this:
Expand Down
11 changes: 9 additions & 2 deletions 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 i = 0;
while (i < birthdays.length) {
if (birthdays[i].includes("July")){
return birthdays[i];
}
i++
}

}

console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th"
14 changes: 13 additions & 1 deletion 2-mandatory/1-weather-report.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*

Imagine we're making a weather app!

We have a list of cities that the user wants to track.
Expand All @@ -12,8 +13,19 @@
*/

function getTemperatureReport(cities) {

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 implementation looks good 👍
As mentioned below, you may just need to check that you're using let or const when declaring a new variable. Even though the code works without it, it's a good habit to get into - otherwise we'll run into problems when we work with larger code bases 😄

// TODO
forecast = []

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

it looks like the result is going to be "underfind". You need ro use special wording to declare a variable.

for(city of cities){

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

same is here, "city" is not declared yet

temperature = temperatureService(city);
information = `The temperature in ${city} is ${temperature} degrees`;
forecast.push(information);
}
return forecast;




}



/* ======= TESTS - DO NOT MODIFY ===== */
Expand Down
58 changes: 53 additions & 5 deletions 2-mandatory/2-financial-times.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,85 @@
Implement the function below, which will return a new array containing only article titles which will fit.
*/
function potentialHeadlines(allArticleTitles) {
// TODO
let titleCharacters = [];

for (let title of allArticleTitles) {

if (title.length<=65) {
titleCharacters.push(title);

}

}
return titleCharacters;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

in my opinion it is perfect code :)





/*
The editor of the FT likes short headlines with only a few words!
Implement the function below, which returns the title with the fewest words.
(you can assume words will always be seperated by a space)
*/
function titleWithFewestWords(allArticleTitles) {

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 almost perfect to me! A couple of very minor points:

  • Are you happy with the variable name shortHeadlines? Maybe think about what value this variable is holding - can you think of a better name for it?
  • It's a good idea to keep an eye on indentation and spacing - this will make it easier for other developers to read your code. Can you see any indentation in this function that could be improved? 😄

// TODO

let shortHeadlines;
let fewestWords;

for (let title of allArticleTitles) {
let numberOfWords = title.split(" ").length;

if (fewestWords === undefined || numberOfWords < fewestWords) {
fewestWords = numberOfWords;
shortHeadlines = title;
}
}
return shortHeadlines;
}




/*
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)
*/
function headlinesWithNumbers(allArticleTitles) {
// TODO
function findingNumber (str){
return /[0-9]/.test(str);

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 this solution! well done 👍

}
function headlinesWithNumbers(allArticleTitles){
let titleWithNumbers = [];
for (let headline of allArticleTitles) {
if (findingNumber(headline)=== true){

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.

When you have an if statement that looks like this: if (findingNumber(headline)=== true){, you can usually re-write it to be if (findingNumber(headline)){.
Can you think of why that works?

titleWithNumbers.push(headline);
}

}
return titleWithNumbers;

}

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 think it is better have function separately, not one inside another, so you can use them any time.


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

return averageNumberOfWords;
}




/* ======= List of Articles - DO NOT MODIFY ===== */
const ARTICLE_TITLES = [
"Streaming wars drive media groups to spend more than $100bn on new content",
Expand Down
41 changes: 37 additions & 4 deletions 2-mandatory/3-stocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,25 @@ 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.

This looks good to me - great job 👍

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

for(let types of closingPricesForAllStocks){
let total = 0;
let average = 0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

maybe it would be better to declare "average" variable outside the "for" function, as it is not used inside it, but outside

for(let i of types) {
total +=i;
}

average = Math.round(total/types.length *100)/100;
averagePrices.push(average);


}
return averagePrices;


}


/*
We also want to see what the change in price is from the first day to the last day for each stock.
Expand All @@ -48,7 +65,14 @@ 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 changesInPrice = [];
for (let types of closingPricesForAllStocks) {
let firstDayPrice = types[0];
let lastDayPrice = types[types.length-1];

changesInPrice.push(Math.round((lastDayPrice - firstDayPrice)*100)/100);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

why do we need here to multiply and the then divide by 100?

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.

Multiplying by 100, using Math.round, and then dividing by 100 is one way to round a number to 2 decimal places in JavaScript. This page goes over a couple of ways you can round a number to 2 decimal places: https://linuxhint.com/round-number-to-2-decimal-places-javascript/

}
return changesInPrice;
}

/*
Expand All @@ -64,7 +88,16 @@ function getPriceChanges(closingPricesForAllStocks) {
The price should be shown with exactly 2 decimal places.
*/
function highestPriceDescriptions(closingPricesForAllStocks, stocks) {
// TODO
let financialReport = [];
let highestPrice = 0;
let stock = 0;
for (let types of closingPricesForAllStocks) {
highestPrice = Math.max(...types).toFixed(2);
financialReport.push (`The highest price of ${stocks[stock].toUpperCase()} in the last 5 days was ${highestPrice}`);
stock++;

}
return financialReport;
}


Expand Down