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 arr[0]; // complete this statement
}

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

/*
Expand Down
2 changes: 1 addition & 1 deletion 1-exercises/C-array-get-set/exercises2.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

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

numbers.push(4);
/*
DO NOT EDIT BELOW THIS LINE
--------------------------- */
Expand Down
4 changes: 3 additions & 1 deletion 1-exercises/D-for-loop/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ const AGES = [
63,
49
];

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

/*
Expand Down
8 changes: 8 additions & 0 deletions 1-exercises/E-while-loop-with-array/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ const BIRTHDAYS = [

function findFirstJulyBDay(birthdays) {
// TODO
let i = 0;
while (i < birthdays.length) {
const birthday = birthdays[i];
if (birthday.includes("July")) {
return birthday;
}
i++;
}
}

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

function getTemperatureReport(cities) {
// TODO
const temperatureReport = [];

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 work 👍


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
17 changes: 16 additions & 1 deletion 2-mandatory/2-financial-times.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,26 @@
*/
function potentialHeadlines(allArticleTitles) {
// TODO
const headTitle = allArticleTitles.filter(title => title.length < 65);

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 is a nice implementation!
I would ask you double-check one thing: the comment above says "65 characters or less". Could you update this code to meet that requirement?

return headTitle;
}

/*
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)
(you can assume words will always be separated by a space)
*/
function titleWithFewestWords(allArticleTitles) {
// TODO
let shortestTitle = allArticleTitles[0];

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 great 😄


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

/*
Expand All @@ -24,6 +35,7 @@ function titleWithFewestWords(allArticleTitles) {
*/
function headlinesWithNumbers(allArticleTitles) {
// TODO
return allArticleTitles.filter(title => /\d/.test(title));
}

/*
Expand All @@ -32,6 +44,9 @@ function headlinesWithNumbers(allArticleTitles) {
*/
function averageNumberOfCharacters(allArticleTitles) {
// TODO
const articleSum = allArticleTitles.reduce((acc, val) => acc + val.length, 0);

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.

Nice use of reduce here!

return Math.round(articleSum / allArticleTitles.length)

}


Expand Down
30 changes: 30 additions & 0 deletions 2-mandatory/3-stocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [
*/
function getAveragePrices(closingPricesForAllStocks) {
// TODO
let currentStock = [];

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 😄
A suggestion: you might be able to improve the readability of this code by creating a separate function which calculates the average for a single stock. Each function will be a little bit simpler, and the new function will have a name - so we can more easily see what it's doing.

for (let i = 0; i < closingPricesForAllStocks.length; i++) {
const numberOfStocks = closingPricesForAllStocks[i].length;
const sumOfCurrentStock = closingPricesForAllStocks[i].reduce((accumulator, currentValue) => accumulator + currentValue, 0);
const roundedStock = Math.round((sumOfCurrentStock / numberOfStocks) * 100) / 100;
currentStock.push(roundedStock);
}
return currentStock;
}

/*
Expand All @@ -49,6 +57,17 @@ function getAveragePrices(closingPricesForAllStocks) {
*/
function getPriceChanges(closingPricesForAllStocks) {
// TODO
let closingPrices = [];

for (let i = 0; i < closingPricesForAllStocks.length; i++) {
const numberOfPrices = closingPricesForAllStocks[i].length - 1;
const firstDay = closingPricesForAllStocks[i].at(0);

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.

It's also possible here to use bracket notation twice. For example, closingPricesForAllStocks[i][0].

const lastDay = closingPricesForAllStocks[i].at(numberOfPrices);
const priceChange = Math.round((lastDay - firstDay) * 100) / 100;

closingPrices.push(priceChange);
}
return closingPrices;
}

/*
Expand All @@ -65,6 +84,17 @@ function getPriceChanges(closingPricesForAllStocks) {
*/
function highestPriceDescriptions(closingPricesForAllStocks, stocks) {
// TODO
let allHighestPrices = [];
for (let i = 0; i < closingPricesForAllStocks.length; i++) {
const stockName = stocks[i].toUpperCase();
const stockPrices = closingPricesForAllStocks[i];
const highestPrice = Math.max(...stockPrices).toFixed(2);

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.

Nice use of Math.max here 👍


allHighestPrices.push(`The highest price of ${stockName} in the last 5 days was ${highestPrice}`)

}

return allHighestPrices;
}


Expand Down
15 changes: 14 additions & 1 deletion 3-extra/1-radio-stations.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,16 @@
*/

// `getAllFrequencies` goes here
function getAllFrequencies() {
const allFrequencies = [
87, 88, 89, 90, 91, 92,
93, 94, 95, 96, 97, 98,
99, 100, 101, 102, 103,
104, 105, 106, 107, 108,
]

return allFrequencies;
}
/**
* Next, let's write a function that gives us only the frequencies that are radio stations.
* Call this function `getStations`.
Expand All @@ -25,7 +34,11 @@
* - Return only the frequencies that are radio stations.
*/
// `getStations` goes here

function getStations() {
const allFrequencies = getAllFrequencies();
const stations = allFrequencies.filter(isRadioStation);
return stations;
}
/*
* ======= TESTS - DO NOT MODIFY =======
* Note: You are not expected to understand everything below this comment!
Expand Down
12 changes: 12 additions & 0 deletions 3-extra/2-array-of-objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@

function getHighestRatedInEachGenre(books) {
// TODO
const highestRatedBooks = {};
for (const book of books) {
const { title, genre, rating } = book;

if (highestRatedBooks[genre] === undefined || rating > highestRatedBooks[genre].rating) {
highestRatedBooks[genre] = { title, rating };
}
}
const highestRatedTitlesByGenre = Object.values(highestRatedBooks).map(book => book.title);

return highestRatedTitlesByGenre;

}


Expand Down
7 changes: 7 additions & 0 deletions 3-extra/3-fibonacci.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@

function generateFibonacciSequence(n) {
// TODO
const sequence = [0, 1];

for (let i = 2; i < n; i++) {
sequence.push(sequence[i - 1] + sequence[i - 2]);
}

return sequence;
}

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