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
13 changes: 8 additions & 5 deletions 1-exercises/A-undefined/exercise.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
By now, you would have already seen "undefined", either in an error message or being output from your program.
But what does it mean? undefined represents the absence of a value.

In some cases, undefined will be used by a programmer intentionally, and they will write code to handle it.
But usually, when you see undefined - it means something has gone wrong!

Expand All @@ -12,25 +12,28 @@
// Example 1
let a;
console.log(a);

/*we saw undefine output because we declared variable and
we didn't assign any value ,that's mean nothing to display.*/

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

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

/* we saw undefine output because function doesn't return or output anything*/

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

sayHelloToUser();
/* we saw undefine output because we didn't assign any value for the variable 'user'
that's mean the variable is empty*/


// Example 4
let arr = [1,2,3];
console.log(arr[3]);
/*we saw undefine we don't have index[3] in the array */
8 changes: 4 additions & 4 deletions 1-exercises/B-array-literals/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
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
--------------------------- */
console.log(numbers);
console.log(mentors);

/*
/*
EXPECTED RESULT
---------------
[1,2,3,4,5,6,7,8,9,10]
Expand Down
8 changes: 4 additions & 4 deletions 1-exercises/C-array-get-set/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
*/

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
}

/*
/*
DO NOT EDIT BELOW THIS LINE
--------------------------- */
let numbers = [1, 2, 3];
Expand All @@ -22,7 +22,7 @@ console.log(first(numbers));
console.log(last(numbers));
console.log(last(names));

/*
/*
EXPECTED RESULT
---------------
1
Expand Down
6 changes: 3 additions & 3 deletions 1-exercises/C-array-get-set/exercises2.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
*/

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

/*
numbers.push(4)
/*
DO NOT EDIT BELOW THIS LINE
--------------------------- */
console.log(numbers);

/*
/*
EXPECTED RESULT
---------------
[1, 2, 3, 4]
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 @@ -27,7 +27,9 @@ const AGES = [
];

// TODO - Write for loop code here

for(let i=0 ;i<AGES.length && i<WRITERS.length; i++){
console.log(`${WRITERS[i]} is ,${AGES[i]} old`);
}
/*
The output should look something like this:

Expand Down
15 changes: 13 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,18 @@ const BIRTHDAYS = [
];

function findFirstJulyBDay(birthdays) {
// TODO
}
let firstJulyBDay = null;
let count=0;
while(count <birthdays.length){
if(birthdays[count] === "July 11th"){
firstJulyBDay = birthdays[count];
}
count++;
}
return firstJulyBDay;

}



console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th"
16 changes: 11 additions & 5 deletions 2-mandatory/1-weather-report.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Imagine we're making a weather app!

We have a list of cities that the user wants to track.
We also already have a temperatureService function which will take a city as a parameter and return a temparature.

Expand All @@ -12,8 +12,11 @@
*/

function getTemperatureReport(cities) {
// TODO
}
return cities.map((city)=>`The temperature in ${city} is ${temperatureService(city)} degrees`);

}


@Muath-Alawadhi Muath-Alawadhi Mar 9, 2023

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You did well! You must remove // TO DO next time



/* ======= TESTS - DO NOT MODIFY ===== */
Expand All @@ -28,10 +31,13 @@ function temperatureService(city) {
temparatureMap.set('Mumbai', 29);
temparatureMap.set('São Paulo', 23);
temparatureMap.set('Lagos', 33);

return temparatureMap.get(city);
}

test('should return array of same length as argument',()=>{
let usersCities = ['London', 'Paris', 'Barcelona'];
expect(getTemperatureReport(usersCities).length).toEqual(3);
})
test("should return a temperature report for the user's cities", () => {
let usersCities = [
"London",
Expand Down
39 changes: 37 additions & 2 deletions 2-mandatory/2-financial-times.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@
Implement the function below, which will return a new array containing only article titles which will fit.
*/
function potentialHeadlines(allArticleTitles) {
let titles=[];
for (let i=0; i<allArticleTitles.length; i++) {
if (allArticleTitles[i].length <= 65) {
titles.push (allArticleTitles[i]);
}
// TODO
}
return titles;
}

/*
Expand All @@ -15,23 +22,51 @@ function potentialHeadlines(allArticleTitles) {
*/
function titleWithFewestWords(allArticleTitles) {
// TODO
let fewestWords =Infinity;
let title='';
for(let i=0; i < allArticleTitles.length; i++){
let words = allArticleTitles[i].split(" ");
if(words.length < fewestWords){
fewestWords = words.length;
title = allArticleTitles[i];
}
}
return title;
}

/*
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
}
let headlines = [];
for (let i = 0; i < allArticleTitles.length; i++) {
if (/\d/.test(allArticleTitles[i])) {
headlines.push(allArticleTitles[i]);
}
}
return headlines;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great using /\d/ .test





/*
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 totalChars = 0;
for(let i=0 ; i < allArticleTitles.length; i++){
totalChars += allArticleTitles[i].length
}

let average = totalChars / allArticleTitles.length;
return Math.round(average);
}


Expand Down
46 changes: 43 additions & 3 deletions 2-mandatory/3-stocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [
We want to understand what the average price over the last 5 days for each stock is.
Implement the below function, which
- Takes this CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS array as input (remember, it's an array of arrays)
- Returns an array containing the average price over the last 5 days for each stock.
- Returns an array containing the average price over the last 5 days for each stock.
For example, the first element of the resulting array should contain Apple’s (aapl) average stock price for the last 5 days.
The second element should be Microsoft's (msft) average price, and so on.
The average value should be rounded to 2 decimal places, and should be a number (not a string)
Expand All @@ -34,8 +34,24 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [
Functions can help with this!
*/
function getAveragePrices(closingPricesForAllStocks) {
// TODO

let days = 5;
let averagePrice = [];
for (let i = 0; i < closingPricesForAllStocks.length; i++) {
let total =0;
for (let j = 0; j < days; j++) {
total += closingPricesForAllStocks[i][j];
}

let avg = total / days;
avg = Math.round(avg * 100) / 100;
averagePrice.push(avg);
}
return averagePrice;

}
// TODO

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 here


/*
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,9 +64,17 @@ 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 days = 5;
let priceChanges = [];
for (let i = 0; i < closingPricesForAllStocks.length; i++) {
let priceChange = closingPricesForAllStocks[i][days - 1] - closingPricesForAllStocks[i][0];
priceChange = Math.round(priceChange * 100) / 100;
priceChanges.push(priceChange);
}
return priceChanges;
}


/*
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,6 +88,22 @@ function getPriceChanges(closingPricesForAllStocks) {
The price should be shown with exactly 2 decimal places.
*/
function highestPriceDescriptions(closingPricesForAllStocks, stocks) {
let descriptions = [];
for (let i = 0; i < closingPricesForAllStocks.length; i++) {
let highest = Math.max(...closingPricesForAllStocks[i]);
let stockTicker = stocks[i].toUpperCase();
let description = `The highest price of ${stockTicker} in the last 5 days was ${highest.toFixed(2)}`;
descriptions.push(description);


}
return descriptions;






// TODO

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WELL DONE!

}

Expand Down