From 7b45a64459db979f3fa6470560b2e5693d806237 Mon Sep 17 00:00:00 2001 From: Felipe Lobo Date: Mon, 12 Apr 2021 10:44:33 -0300 Subject: [PATCH 1/3] resolvendo exercicios do dia 1 --- solutions/day-01/script.js | 72 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 solutions/day-01/script.js diff --git a/solutions/day-01/script.js b/solutions/day-01/script.js new file mode 100644 index 0000000..21b00fa --- /dev/null +++ b/solutions/day-01/script.js @@ -0,0 +1,72 @@ +// Exercise: Level 1 + +const countries = [ + 'Albania', + 'Bolivia', + 'Canada', + 'Denmark', + 'Ethiopia', + 'Finland', + 'Germany', + 'Hungary', + 'Ireland', + 'Japan', + 'Kenya', + ] + + const webTechs = [ + 'HTML', + 'CSS', + 'JavaScript', + 'React', + 'Redux', + 'Node', + 'MongoDB', + ] + +// Declare an empty array; +const emptyArray = []; + +// Declare an array with more than 5 number of elements +const arrayWithFiveElements = [5, 4, 3, 2, 1]; + +// Find the length of your array +arrayWithFiveElements.length; + +// Get the first item, the middle item and the last item of the array +const firtItem = arrayWithFiveElements[0]; +const middleItem = arrayWithFiveElements[Math.floor(arrayWithFiveElements.length / 2)]; +const lastItem = arrayWithFiveElements[arrayWithFiveElements.length - 1]; + +// Declare an array called mixedDataTypes, put different data types in the array and find the length of the array. The array size should be greater than 5 +const mixedDataTypes = ['hi', 5, true, 'book', { 1: 5, 2: 3, 3: 2}, 4, 1]; +mixedDataTypes.length; + +// Declare an array variable name itCompanies and assign initial values Facebook, Google, Microsoft, Apple, IBM, Oracle and Amazon +let itCompanies = ['Facebook', 'Google', 'Microsoft', 'Apple', 'IBM', 'Oracle','Amazon']; + +// Print the array using console.log() +console.log(itCompanies); + +// Print the number of companies in the array +console.log(itCompanies.length); + +// Print the first company, middle and last company +const firstCompany = itCompanies[0]; +const middleCompany = itCompanies[Math.floor(itCompanies.length / 2)]; +const lastCompany = itCompanies[Math.floor(itCompanies.length - 1)] + +// Print out each company +// Change each company name to uppercase one by one and print them out +// Print the array like as a sentence: Facebook, Google, Microsoft, Apple, IBM,Oracle and Amazon are big IT companies. +// Check if a certain company exists in the itCompanies array. If it exist return the company else return a company is not found +// Filter out companies which have more than one 'o' without the filter method +// Sort the array using sort() method +// Reverse the array using reverse() method +// Slice out the first 3 companies from the array +// Slice out the last 3 companies from the array +// Slice out the middle IT company or companies from the array +// Remove the first IT company from the array +// Remove the middle IT company or companies from the array +// Remove the last IT company from the array +// Remove all IT companies \ No newline at end of file From ea6790666ac1e102ef4884ccb69720d203465f48 Mon Sep 17 00:00:00 2001 From: Felipe Lobo Date: Mon, 12 Apr 2021 11:00:23 -0300 Subject: [PATCH 2/3] Update script.js --- solutions/day-01/script.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/solutions/day-01/script.js b/solutions/day-01/script.js index 21b00fa..2e1b953 100644 --- a/solutions/day-01/script.js +++ b/solutions/day-01/script.js @@ -56,17 +56,41 @@ const firstCompany = itCompanies[0]; const middleCompany = itCompanies[Math.floor(itCompanies.length / 2)]; const lastCompany = itCompanies[Math.floor(itCompanies.length - 1)] +console.log('firstCompany: ', firstCompany, '; middleCompany: ', middleCompany, '; lastCompany: ', lastCompany); + // Print out each company +for (let i = 0; i < itCompanies.length; i++) { + console.log(itCompanies[i]); +} + // Change each company name to uppercase one by one and print them out +let companies = []; +for (let i = 0; i < itCompanies.length; i++) { + let uppercaseCompany = itCompanies[i].toUpperCase(); + companies.push(uppercaseCompany) +} +console.log(companies); + // Print the array like as a sentence: Facebook, Google, Microsoft, Apple, IBM,Oracle and Amazon are big IT companies. + // Check if a certain company exists in the itCompanies array. If it exist return the company else return a company is not found + // Filter out companies which have more than one 'o' without the filter method + // Sort the array using sort() method + // Reverse the array using reverse() method + // Slice out the first 3 companies from the array + // Slice out the last 3 companies from the array + // Slice out the middle IT company or companies from the array + // Remove the first IT company from the array + // Remove the middle IT company or companies from the array + // Remove the last IT company from the array + // Remove all IT companies \ No newline at end of file From f578b6a76611b6140c3ceb39623e4149344ee315 Mon Sep 17 00:00:00 2001 From: Felipe Lobo Date: Mon, 12 Apr 2021 14:04:56 -0300 Subject: [PATCH 3/3] =?UTF-8?q?Continuando=20exerc=C3=ADcio=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- solutions/day-01/script.js | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/solutions/day-01/script.js b/solutions/day-01/script.js index 2e1b953..14b1796 100644 --- a/solutions/day-01/script.js +++ b/solutions/day-01/script.js @@ -1,28 +1,4 @@ -// Exercise: Level 1 - -const countries = [ - 'Albania', - 'Bolivia', - 'Canada', - 'Denmark', - 'Ethiopia', - 'Finland', - 'Germany', - 'Hungary', - 'Ireland', - 'Japan', - 'Kenya', - ] - - const webTechs = [ - 'HTML', - 'CSS', - 'JavaScript', - 'React', - 'Redux', - 'Node', - 'MongoDB', - ] +// Exercise: Level 1 - Arrays // Declare an empty array; const emptyArray = []; @@ -72,9 +48,14 @@ for (let i = 0; i < itCompanies.length; i++) { console.log(companies); // Print the array like as a sentence: Facebook, Google, Microsoft, Apple, IBM,Oracle and Amazon are big IT companies. +console.log(`${itCompanies[0]}, ${itCompanies[1]}, ${itCompanies[2]}, ${itCompanies[3]}, ${itCompanies[4]}, ${itCompanies[5]}, and ${itCompanies[6]} are big IT companies.`) + // Check if a certain company exists in the itCompanies array. If it exist return the company else return a company is not found +let companyIndex = itCompanies.indexOf(company); +companyIndex === -1 ? console.log(`${company} is not found.`) : console.log(`${company}`) + // Filter out companies which have more than one 'o' without the filter method // Sort the array using sort() method