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
10 changes: 10 additions & 0 deletions 1-exercises/A-undefined/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,34 @@
let a;
console.log(a);

//// a has been declared without value


// Example 2
function sayHello() {
let message = "Hello";

}

let hello = sayHello();
console.log(hello);

// function sayHello has been declared without return value


// Example 3
function sayHelloToUser(user) {
console.log(`Hello ${user}`);
}

sayHelloToUser();
// function sayHelloToUser is being called without an argument




// Example 4
let arr = [1,2,3];
console.log(arr[3]);

// arr [3] doesn't have a value.
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 @@ -3,9 +3,9 @@
--------------
Declare some variables assigned to arrays of values
*/
let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let mentors = ["Daniel", "Irina", "Rares"];

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

/*
DO NOT EDIT BELOW THIS LINE
Expand Down
12 changes: 8 additions & 4 deletions 1-exercises/C-array-get-set/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
Complete the functions below to get the first and last values from the array
*/

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

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

function last(names) {
return names[names.length-1];
}

/*
Expand Down
3 changes: 2 additions & 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,8 @@
*/

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

numbers.push(4);
numbers[0] = 1;
/*
DO NOT EDIT BELOW THIS LINE
--------------------------- */
Expand Down
9 changes: 5 additions & 4 deletions 1-exercises/D-for-loop/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,24 @@
Using a for loop, output to the console a line about the age of each writer.
*/

const WRITERS = [
const writers = [
"Virginia Woolf",
"Zadie Smith",
"Jane Austen",
"Bell Hooks",
"Yukiko Motoya"
]

const AGES = [
const ages = [
59,
40,
41,
63,
49
];

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

/*
The output should look something like this:
Expand Down
12 changes: 9 additions & 3 deletions 1-exercises/E-while-loop-with-array/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Use a while loop to search through the array until you find the first birthday in July, then return that birthday from the function.
*/

const BIRTHDAYS = [
const birthdays = [
"January 7th",
"February 12th",
"April 3rd",
Expand All @@ -17,7 +17,13 @@ const 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"
console.log(findFirstJulyBDay(birthdays)); // should output "July 11th"
6 changes: 5 additions & 1 deletion 2-mandatory/1-weather-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
*/

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

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


Expand Down
43 changes: 39 additions & 4 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.

Looks perfect!
One small point - just keep an eye on indentation (spacing). This will make it easier for other developers to read your code.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

thanks, i will fix it .

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

/*
Expand All @@ -14,24 +20,53 @@ function potentialHeadlines(allArticleTitles) {
(you can assume words will always be seperated by a space)
*/
function titleWithFewestWords(allArticleTitles) {
// TODO
let shortestHeadline;
let fewestNumberOfWords;
for(let title of allArticleTitles){
let numberOfWords = title.split(' ').length;
if (fewestNumberOfWords === undefined || numberOfWords < fewestNumberOfWords){

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

good job! you have used || in if function but I have used greater > in if function.

fewestNumberOfWords=numberOfWords;
shortestHeadline = title;
}
}
return shortestHeadline;
}


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

This looks good 👍
I like that you used a separate function to check if the string contains a number - it makes the code more readable 😄
One small point: when you have code like this - if (containsNumbers(title)== true) {, you can also write it like this if (containsNumbers(title)) {. Can you think of why that is?

function containsNumbers(str) {
return /[0-9]/.test(str);
}

function headlinesWithNumbers(allArticleTitles) {
// TODO
let titlesWithNumbers = [];

for(let title of allArticleTitles){
if (containsNumbers(title)== true) {
titlesWithNumbers.push(title);
}

}

return titlesWithNumbers;
}

/*
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 countAllWords = 0;
let noOfArticles = allArticleTitles.length;
for(let title of allArticleTitles){
countAllWords = countAllWords + title.length;
}
let averageWords = Math.round(countAllWords/noOfArticles);
return averageWords;
}


Expand Down
36 changes: 33 additions & 3 deletions 2-mandatory/3-stocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,21 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [
Functions can help with this!
*/
function getAveragePrices(closingPricesForAllStocks) {
// TODO
let averagePrices = [];
for(let item of closingPricesForAllStocks){
let sum = 0;
let average = 0;
for(let i of item) {
sum +=i;
}

average = Math.round(sum/item.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 +61,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 priceChange = [];
for(let item of closingPricesForAllStocks){
let firstDayPrice = item[0];
let lastDayPrice = item[item.length-1];
priceChange.push(Math.round((lastDayPrice - firstDayPrice)*100)/100);

}
return priceChange;
}

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




/* ======= TESTS - DO NOT MODIFY ===== */
test("should return the average price for each stock", () => {
expect(getAveragePrices(CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS)).toEqual(
Expand Down
18 changes: 16 additions & 2 deletions 3-extra/1-radio-stations.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@
* - Should return this array to use in other functions
*/

// `getAllFrequencies` goes here
function getAllFrequencies(){
let listOfFrequencies = [];
for (let i =87; i<=108; i++) {
listOfFrequencies.push(i);
}
return listOfFrequencies;
}

/**
* Next, let's write a function that gives us only the frequencies that are radio stations.
Expand All @@ -24,7 +30,15 @@
* - There is a helper function called isRadioStation that takes an integer as an argument and returns a boolean.
* - Return only the frequencies that are radio stations.
*/
// `getStations` goes here
function getStations(){
let stations = [];
for (let item of getAllFrequencies()){
if(isRadioStation (item)){
stations.push(item);
}
}
return stations;
}

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