diff --git a/1-exercises/A-array-find/exercise.js b/1-exercises/A-array-find/exercise.js index 35902fed..3eb6a776 100644 --- a/1-exercises/A-array-find/exercise.js +++ b/1-exercises/A-array-find/exercise.js @@ -5,6 +5,7 @@ // write your code here + let names = [ "Rakesh", "Antonio", @@ -17,6 +18,14 @@ let names = [ "Ahmed", ]; +function isLongNameAndStartsWithA(name) { + return name.length > 7 && name[0] == "A"; +} +function findLongNameThatStartsWithA(names){ + return names.find(isLongNameAndStartsWithA); + +} + let longNameThatStartsWithA = findLongNameThatStartsWithA(names); console.log(longNameThatStartsWithA); diff --git a/1-exercises/B-array-some/exercise.js b/1-exercises/B-array-some/exercise.js index fddc69ee..7d9b9e08 100644 --- a/1-exercises/B-array-some/exercise.js +++ b/1-exercises/B-array-some/exercise.js @@ -8,10 +8,19 @@ let pairsByIndex = [[0, 3], [1, 2], [2, 1], null, [3, 0]]; +//*************************************************** + +function isNullvalue(!number) { + return !number; +} + +//*************************************************** + // If there is a null value in the array exit the program with the error code // https://nodejs.org/api/process.html#process_process_exit_code // process.exit(1); + let students = ["Islam", "Lesley", "Harun", "Rukmini"]; let mentors = ["Daniel", "Irina", "Mozafar", "Luke"]; diff --git a/1-exercises/C-array-every/exercise.js b/1-exercises/C-array-every/exercise.js index 347b9632..cb22040d 100644 --- a/1-exercises/C-array-every/exercise.js +++ b/1-exercises/C-array-every/exercise.js @@ -5,7 +5,11 @@ let students = ["Omar", "Austine", "Dany", "Swathi", "Lesley", "Rukmini"]; let group = ["Austine", "Dany", "Swathi", "Daniel"]; -let groupIsOnlyStudents; // complete this statement +let groupIsOnlyStudents = group.every(students);{ +return students.includes(students); +} +console.log(groupIsOnlyStudents); + if (groupIsOnlyStudents) { console.log("The group contains only students"); diff --git a/1-exercises/D-array-filter/exercise.js b/1-exercises/D-array-filter/exercise.js index 51837028..bb3139e8 100644 --- a/1-exercises/D-array-filter/exercise.js +++ b/1-exercises/D-array-filter/exercise.js @@ -8,7 +8,10 @@ let pairsByIndexRaw = [[0, 3], [1, 2], [2, 1], null, [1], false, "whoops"]; -let pairsByIndex; // Complete this statement +let pairsByIndex = pairsByIndexRaw.filter( item => item.length === 2); + + +// Complete this statement let students = ["Islam", "Lesley", "Harun", "Rukmini"]; let mentors = ["Daniel", "Irina", "Mozafar", "Luke"]; diff --git a/1-exercises/E-array-map/exercise.js b/1-exercises/E-array-map/exercise.js index 5a157279..b5ba4a35 100644 --- a/1-exercises/E-array-map/exercise.js +++ b/1-exercises/E-array-map/exercise.js @@ -3,7 +3,7 @@ let numbers = [0.1, 0.2, 0.3, 0.4, 0.5]; -let numbersMultipliedByOneHundred; // complete this statement +let numbersMultipliedByOneHundred = numbers.map(number => number * 100); // complete this statement console.log(numbersMultipliedByOneHundred); diff --git a/1-exercises/G-array-methods/exercise.js b/1-exercises/G-array-methods/exercise.js index 4367ef6e..bc504f2a 100644 --- a/1-exercises/G-array-methods/exercise.js +++ b/1-exercises/G-array-methods/exercise.js @@ -4,7 +4,7 @@ */ let numbers = [3, 2, 1]; -let sortedNumbers; // complete this statement +let sortedNumbers = numbers.sort(); // complete this statement /* DO NOT EDIT BELOW THIS LINE diff --git a/1-exercises/G-array-methods/exercise2.js b/1-exercises/G-array-methods/exercise2.js index 4c68c3a6..66d9b1ab 100644 --- a/1-exercises/G-array-methods/exercise2.js +++ b/1-exercises/G-array-methods/exercise2.js @@ -7,8 +7,7 @@ let mentors = ["Daniel", "Irina", "Rares"]; let students = ["Rukmini", "Abdul", "Austine", "Swathi"]; -let everyone; // complete this statement - +let everyone = mentors.concat(students); /* DO NOT EDIT BELOW THIS LINE --------------------------- */ diff --git a/1-exercises/H-array-methods-2/exercise.js b/1-exercises/H-array-methods-2/exercise.js index 59c5daa7..cab72be3 100644 --- a/1-exercises/H-array-methods-2/exercise.js +++ b/1-exercises/H-array-methods-2/exercise.js @@ -15,8 +15,8 @@ let everyone = [ "Swathi", ]; -let firstFive; // complete this statement -let lastFive; // complete this statement +let firstFive = everyone.slice(0, 5);// complete this statement +let lastFive = everyone.slice(2, 7);// complete this statement /* DO NOT EDIT BELOW THIS LINE diff --git a/1-exercises/H-array-methods-2/exercise2.js b/1-exercises/H-array-methods-2/exercise2.js index 14bb4318..aec63046 100644 --- a/1-exercises/H-array-methods-2/exercise2.js +++ b/1-exercises/H-array-methods-2/exercise2.js @@ -6,8 +6,16 @@ For example, capitailise("hello") should return "Hello" Tip: use the string method .split() and the array method .join() */ +//****** +//originanl: +//function capitalise(str) {} +//******* -function capitalise(str) {} +function capitalise(str){ +let uppercase = str.split(""); +uppercase[0] = uppercase[0].toUpperCase(); +return uppercase.join(""); +} /* DO NOT EDIT BELOW THIS LINE diff --git a/1-exercises/H-array-methods-2/exercise3.js b/1-exercises/H-array-methods-2/exercise3.js index c8e079e4..7279417e 100644 --- a/1-exercises/H-array-methods-2/exercise3.js +++ b/1-exercises/H-array-methods-2/exercise3.js @@ -7,7 +7,7 @@ let ukNations = ["Scotland", "Wales", "England", "Northern Ireland"]; function isInUK(country) { - return; // complete this statement + return ukNations.includes(country); // complete this statement } /* diff --git a/1-exercises/I-string-replace/exercise.js b/1-exercises/I-string-replace/exercise.js index 3f7104d7..bbc425e3 100644 --- a/1-exercises/I-string-replace/exercise.js +++ b/1-exercises/I-string-replace/exercise.js @@ -13,7 +13,8 @@ let story = "I like dogs. One day I went to the park and I saw 10 dogs. It was a great day."; -let result = story.replace("", ""); +let result = story.replace("dogs"); +console.log(result); /* EXPECTED OUTPUT */ diff --git a/1-exercises/J-string-substring/exercise.js b/1-exercises/J-string-substring/exercise.js index 4624db68..073380a6 100644 --- a/1-exercises/J-string-substring/exercise.js +++ b/1-exercises/J-string-substring/exercise.js @@ -6,9 +6,9 @@ let statement = "I like programming and dogs"; -statement = statement.substring(); +let newStatement = statement.substring(0, 19); -console.log(statement); +console.log(newStatement); /* EXPECTED OUTPUT diff --git a/1-exercises/J-string-substring/exercise2.js b/1-exercises/J-string-substring/exercise2.js index a1d9bf62..ea13ad22 100644 --- a/1-exercises/J-string-substring/exercise2.js +++ b/1-exercises/J-string-substring/exercise2.js @@ -3,7 +3,9 @@ You should log only the peoples first names. - For example, if the name is "John Smith" you should return "John" + For example, if the name is "John Smith" you + + should return "John" */ let names = [ @@ -14,11 +16,11 @@ let names = [ "Arron Graham", ]; -names[0] = names[0].substring(); -names[1] = names[1].substring(); -names[2] = names[2].substring(); -names[3] = names[3].substring(); -names[4] = names[4].substring(); +names[0] = names[0].substring(0, 6); +names[1] = names[1].substring(0, 6); +names[2] = names[2].substring(0, 5); +names[3] = names[3].substring(0, 5); +names[4] = names[4].substring(0, 5); names.forEach((name) => { console.log(name); diff --git a/1-exercises/J-string-substring/exercise3.js b/1-exercises/J-string-substring/exercise3.js index 14f77417..01d95088 100644 --- a/1-exercises/J-string-substring/exercise3.js +++ b/1-exercises/J-string-substring/exercise3.js @@ -8,7 +8,7 @@ let statement = "I do not like programming"; -let result = ""; +let result = statement.substring(0, 4)+statement.substring(8, statement.length); console.log(result); diff --git a/2-mandatory/1-create-functions.js b/2-mandatory/1-create-functions.js index 6df12961..281a6854 100644 --- a/2-mandatory/1-create-functions.js +++ b/2-mandatory/1-create-functions.js @@ -3,7 +3,11 @@ Write a function that: - Accepts an array as a parameter. - Returns a new array containing the first five elements of the passed array. */ -function first5() { + +//let first5 = groceries.slice(0,5); + +function first5(item) { + return item.slice(0, 5); } /* @@ -11,7 +15,9 @@ Write a function that: - Accepts an array as a parameter. - Returns a new array containing the same elements, except sorted. */ -function sortArray() { +function sortArray(array) { + const newArr = array.filter((e) => e).sort(); + return newArr; } /* @@ -19,12 +25,22 @@ NOTE: This exercise is the same as one you did last week - try to do it again us Think about what is better about this solution than your one last week, and what is worse. Write a function that: -- Takes an array of strings as input. +- Takes an array of strings as input.✔ - Removes any spaces in the beginning or end each string. - Removes any forward slashes (/) in the strings. - Makes the strings all lowercase. */ -function tidyUpString() { + +function tidyUpString(strings) { + const arr = []; + for (let i = 0; i < strings.length; i += 1) { + const string = strings[i]; + arr.push(string + .trim() + .replace("/", '') + .toLowerCase()); + } + return arr; } /* @@ -33,7 +49,8 @@ Write a function that: - Returns a new array containing the same elements, but without the element at the passed index. */ -function remove() { +function remove(array, id) { + return array.filter((elem, index) => index !==id); } /* @@ -44,9 +61,16 @@ Write a function that: - Numbers greater 100 must be replaced with 100. */ -function formatPercentage() { -} - +function formatPercentage(numbers) { + return numbers.map((number) => { + if (number > 100) { + number = 100; + } + return `${Number(number.toFixed(2))}%` +}); + + } + /* ======= TESTS - DO NOT MODIFY ===== */ test("first5 function works for more than five elements", () => { diff --git a/2-mandatory/2-oxygen-levels.js b/2-mandatory/2-oxygen-levels.js index 5711c5e5..bda8d68d 100644 --- a/2-mandatory/2-oxygen-levels.js +++ b/2-mandatory/2-oxygen-levels.js @@ -11,7 +11,22 @@ Some string methods that might help you here are .replace() and .substring(). */ -function findSafeOxygenLevel() {} + + +function findSafeOxygenLevel(planets) { + for (let i = 0; i < planets.length; i++) { + const string = planets[i]; + if (string.includes('%')) { + const number = string.replace("%", ""); + const oxigenLevel = Number(number); + if (oxigenLevel > 19.5 && oxigenLevel < 23.5 ){ + return number + '%' + + } + } + } +} + /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/2-mandatory/3-bush-berries.js b/2-mandatory/3-bush-berries.js index b434a507..0a1f94a0 100644 --- a/2-mandatory/3-bush-berries.js +++ b/2-mandatory/3-bush-berries.js @@ -20,10 +20,23 @@ Let's first look at an example that will teach you how to use these methods. */ +//pink berries only safe to eat +//other berries not safe to eat +//Create a function which checks if the bush has ALL PINK berries and is safe for the astronauts to eat from the bush. +//Use the tests to confirm which message to return function isBushSafe(berryArray) { + //for (let safeBerries = pink; index = berryArray;) { + const safeBerries = berryArray.filter ((pink) => pink).sort(); + return safeBerries; + + } //Write your code here -} +//for (let index = 0; index < array.length; index++) { + //const element = array[index]; + + + /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/2-mandatory/4-space-colonies.js b/2-mandatory/4-space-colonies.js index 30095213..f75a6ebd 100644 --- a/2-mandatory/4-space-colonies.js +++ b/2-mandatory/4-space-colonies.js @@ -14,8 +14,15 @@ Logic: Only strings that start with A, and finish with family */ +//in planet "Alpha" the families who start whit A should stay the others will search for +//other planets +//Create a function that returns an array of colonisers. +//hint empieza por A y debe de contener la palabra family al final + +function getSettlers(voyager) { + return voyager.includes("family") && voyagers[0] == "A"; +} -function getSettlers() {} /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/2-mandatory/5-eligible-students.js b/2-mandatory/5-eligible-students.js index f92478e0..e9d90dfa 100644 --- a/2-mandatory/5-eligible-students.js +++ b/2-mandatory/5-eligible-students.js @@ -7,7 +7,16 @@ - Returns an array containing only the names of the who have attended AT LEAST 8 classes */ -function getEligibleStudents() {} +function getEligibleStudents(students) { + let optIn =[]; + for (let eligeble = 0; eligeble < students.legth; eligeble++){ + if (students[elegible][1]>=8){ + optIn.push(students[eligeble][0]); + } + } + return optIn; +} + /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/2-mandatory/6-journey-planner.js b/2-mandatory/6-journey-planner.js index 25a14083..6765499a 100644 --- a/2-mandatory/6-journey-planner.js +++ b/2-mandatory/6-journey-planner.js @@ -20,8 +20,8 @@ function checkCodeIsThere(stringText) { let magicWord = "code"; //edit code below - if (stringText) { - return stringText; + if (stringText.includes("code")) { + return stringText.indexOf("code"); } else { return "Not found"; } @@ -64,7 +64,9 @@ function checkCodeIsThere(stringText) { Hint: Use the corresponding array method to split the array. */ -function getTransportModes() {} +function getTransportModes(location) { + return location.slice(1); +} /* Implement the function isAccessibleByTransportMode that @@ -81,7 +83,9 @@ function getTransportModes() {} Hint: Use the corresponding array method to decide if an element is included in an array. */ -function isAccessibleByTransportMode() {} +function isAccessibleByTransportMode(transportPlace, transport) { + return transportPlace.includes(transport); +} /* Implement the function getLocationName that @@ -92,7 +96,9 @@ function isAccessibleByTransportMode() {} - Returns the name of the location e.g: "Tower Bridge" */ -function getLocationName() {} +function getLocationName(location) { + return location[0]; +} /* We arrived at the final method. it won't take long if you use the previously implemented functions wisely. @@ -121,8 +127,9 @@ function getLocationName() {} Advanced challange: try to use arrow function when invoking an array method. */ -function journeyPlanner(locations, transportMode) { +function journeyPlanner(location, transport) { // Implement the function body + return location.filter(( location => location.includes(transport))) } /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/2-mandatory/7-lane-names.js b/2-mandatory/7-lane-names.js index 40c31b68..512127ec 100644 --- a/2-mandatory/7-lane-names.js +++ b/2-mandatory/7-lane-names.js @@ -6,7 +6,9 @@ HINT: string and array methods that could be helpful (indexOf, filter) */ -function getLanes() {} +function getLanes(streets) { + return streets.filter(name=>name.includes("Lane")); +} /* ======= TESTS - DO NOT MODIFY ===== */