From 7b45a64459db979f3fa6470560b2e5693d806237 Mon Sep 17 00:00:00 2001 From: Felipe Lobo Date: Mon, 12 Apr 2021 10:44:33 -0300 Subject: [PATCH] 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