diff --git a/src/advanced.js b/src/advanced.js index 72434e1..0ca18bf 100644 --- a/src/advanced.js +++ b/src/advanced.js @@ -5,32 +5,59 @@ const numsToMerge = [...nums] const arrayToExtend = [...nums] // 1. Set this variable to the sum of the first and last numbers in the nums array -const firstPlusLast = 0 +const firstPlusLast = nums[0] + nums[8] + +console.log(firstPlusLast) // 2. set this variable to the index where the number 14 is located in the array -const indexOfFourteen = 0 + +const indexOfFourteen = nums.indexOf(14) + +console.log(indexOfFourteen) // 3. remove the last 3 elements of the array in one single instruction -const withoutLastThree = 0 + +const withoutLastThree = nums.slice(0, -3) + +console.log(withoutLastThree) // 4. Add the number 15 before the number 8 in the array arrayToExtend + +const indexofeight = nums.indexOf(8) + +nums.splice(indexofeight, 0, 15) + +console.log(nums) + // note: use splice, read the documentation carefully // 5. check if the array includes the number 100 -const includesHundred = true + +const includesHundred = nums.includes(100) + +console.log(includesHundred) // 6. extract the numbers 7, 3, 8 into a new array -const withSevenThreeEight = [] + +const withSevenThreeEight = [7, 3, 8] + +console.log(withSevenThreeEight) // 7. add the numbers from otherNums to the end of numsToMerge -const combinedNums = [] + +const combinedNums = [...numsToMerge, ...otherNums] + +console.log(combinedNums) // 8. create a new array with the cities 'Rome', 'Paris' and 'Barcelona' -const newCities = [] +const newCities = ['Rome', 'Paris', 'Barcelona'] // 9. use the spread operator ... to clone the cities array and add 'Berlin' to the end and 'Sydney' to the start // note: read about the spread operator -const moreCities = [] + +const moreCities = ['Sydney', ...newCities, 'Berlin'] + +console.log(moreCities) module.exports = { a: firstPlusLast, diff --git a/src/core.js b/src/core.js index 11bda56..0c4479e 100644 --- a/src/core.js +++ b/src/core.js @@ -3,22 +3,48 @@ const teachers = ['Nathan', 'Ed', 'Steve', 'Phil', 'Carlo', 'Lewis', 'Shahzad'] // 1. Using an index on the teachers array, change the value of the // fourthTeacher variable below to be the fourth teacher listed in the array -const fourthTeacher = undefined + +const fourthTeacher = teachers[3] + +console.log(fourthTeacher) // 2. Replace the fifth teacher in the teachers array with 'Patrick' +const newteacher = 'Patrick' + +teachers[4] = newteacher + +console.log(teachers) // 3. Remove the last teacher from the array and save them in lastTeacher below -const lastTeacher = undefined +const lastTeacher = teachers.pop() // done + +console.log(lastTeacher) +console.log(teachers) // 4. Remove the first teacher from the array and save them in firstTeacher below -const firstTeacher = undefined +const firstTeacher = teachers.shift() + +console.log(firstTeacher) +console.log(teachers) // 5. Add a teacher named 'Vanessa' to the end of the teachers array +teachers.push('Vanessa') + +console.log(teachers) + // 6. Remove 'Ed' from the teachers array +teachers.shift('Ed') + +console.log(teachers) + // 7. Add a teacher named 'Sarah' to the beginning of the teachers array +teachers.unshift('Sarah') + +console.log(teachers) + // Don't change the code below this line module.exports = { teachers, diff --git a/src/extension.js b/src/extension.js index 6482719..2b1533f 100644 --- a/src/extension.js +++ b/src/extension.js @@ -9,18 +9,44 @@ const fruits = ['Apple', 'Orange', 'Pear'] // 1. Add Fred to the names array +names.unshift('Fred') + +console.log(names) + // 2. Add 4 to the end of the numbers array +numbers.push(4) + +console.log(numbers) + // 3. Add Rio to the start of the cities array +cities.unshift('Rio') + +console.log(cities) + // 4. Remove the first colour from the colours array +colours.shift() + +console.log(colours) + // 5. Remove the last item from the keys array +keys.pop() + +console.log(keys) + // 6. Remove Jordan from the countries array +countries.splice(1, 1) + +console.log(countries) + // 7. Remove the last fruit from the fruits array and store it in pear below -const pear = undefined +const pear = fruits.pop() + +console.log(fruits) // Do not change the code below module.exports = {