diff --git a/week-2/Homework/K-array-methods/README.md b/week-2/Homework/K-array-methods/README.md deleted file mode 100644 index cc568c23b..000000000 --- a/week-2/Homework/K-array-methods/README.md +++ /dev/null @@ -1,55 +0,0 @@ -Do you remember how strings have special functions called methods? Don't worry if not! Here's an example to jog your memory: - -```sh -$ node -> var name = "Daniel" -undefined -> name.toLowerCase() -daniel -``` - -Arrays also have several methods that you can use. - -### `.sort()` - -_An array method that sorts the values in an array into ascending alphabetical or numerical order._ - -```js -var unorderedLetters = ["z", "v", "b", "f", "g"]; -var orderedLetters = unorderedLetters.sort(); - -var unorderedNumbers = [8, 5, 1, 4, 2]; -var orderedNumbers = unorderedNumbers.sort(); - -console.log(orderedLetters); // logs [ 'b', 'f', 'g', 'v', 'z' ] -console.log(unorderedLetters); // logs [ 'b', 'f', 'g', 'v', 'z' ] -console.log(orderedNumbers); // logs [ 1, 2, 4, 5, 8 ] -console.log(unorderedNumbers); // logs [ 1, 2, 4, 5, 8 ] -``` - -> When you call this array method it uses the array on the left side of the dot as an input, and it sorts that array also returning it. Note how both ordered and unordered arrays are sorted now! - -### `.concat()` - -_Adds (or concatenates) another value or array to the array._ - -```sh -$ node -> var arr = [1, 2, 3] -undefined -> arr.concat(4) -[1, 2, 3, 4] -> arr -[1, 2, 3] -``` - -Did you notice how calling the concat method did not change `arr`? This is because `concat`, like most array methods, returns a _new_ array, it does not alter the one you called the method on. - -If you wan to use the array returned by calling `.concat()` you should store it in a new variable. - -```js -var arr = [1, 2, 3]; -var newArr = arr.concat(4); - -console.log(newArr); // logs [1, 2, 3, 4] -``` diff --git a/week-2/Homework/K-array-methods/exercise.js b/week-2/Homework/K-array-methods/exercise.js deleted file mode 100644 index 44e9c8012..000000000 --- a/week-2/Homework/K-array-methods/exercise.js +++ /dev/null @@ -1,19 +0,0 @@ -/* - Array methods - sort - -------------------- -*/ - -var numbers = [3, 2, 1]; -var sortedNumbers; // complete this statement - -/* - DO NOT EDIT BELOW THIS LINE - --------------------------- */ - -console.log(sortedNumbers); - -/* - EXPECTED RESULT - --------------- - [1, 2, 3] -*/ diff --git a/week-2/Homework/K-array-methods/exercise2.js b/week-2/Homework/K-array-methods/exercise2.js deleted file mode 100644 index 3dd24a17a..000000000 --- a/week-2/Homework/K-array-methods/exercise2.js +++ /dev/null @@ -1,22 +0,0 @@ -/* - Array methods - concat - ---------------------- - The variable everyone should be an array containing both mentors and students. -*/ - -var mentors = ["Daniel", "Irina", "Rares"]; -var students = ["Rukmini", "Abdul", "Austine", "Swathi"]; - -var everyone; // complete this statement - -/* - DO NOT EDIT BELOW THIS LINE - --------------------------- */ - -console.log(everyone); - -/* - EXPECTED RESULT - --------------- - ["Daniel", "Irina", "Rares", "Rukmini", "Abdul", "Austine", "Swathi"] -*/ diff --git a/week-2/Homework/N-array-properties/README.md b/week-2/Homework/K-array-properties/README.md similarity index 100% rename from week-2/Homework/N-array-properties/README.md rename to week-2/Homework/K-array-properties/README.md diff --git a/week-2/Homework/N-array-properties/exercise.js b/week-2/Homework/K-array-properties/exercise.js similarity index 100% rename from week-2/Homework/N-array-properties/exercise.js rename to week-2/Homework/K-array-properties/exercise.js diff --git a/week-2/Homework/L-array-methods-2/README.md b/week-2/Homework/L-array-methods-2/README.md deleted file mode 100644 index 507de3192..000000000 --- a/week-2/Homework/L-array-methods-2/README.md +++ /dev/null @@ -1,46 +0,0 @@ -Let's explore some more array methods. - -### `.slice()` - -_Returns a slice of the array._ - -You can tell `.slice()` where you want the slice to begin and end by passing it two parameters. - -```sh -$ node -> var arr = [0, 1, 2, 3, 4] -undefined -> arr.slice(0, 2) -[0, 1] -> ["a", "b", "c", "d"].slice(1, 2) -['b'] -``` - -### `.includes()` - -_Returns true if a value is in the array._ - -```js -var mentors = ["Daniel", "Irini", "Ashleigh", "Rob", "Etzali"]; - -function isAMentor(name) { - return mentors.includes(name); -} - -consooe.log("Is Rukmuni a mentor?"); -console.log(isAMentor("Rukmini")); // logs false -``` - -### `.join()` - -_Returns all the array values joined together in a string. By default, this method takes no parameters and then the elements are divided with a comma `,`. If you provide it with a string parameter though, then it becomes the divider of the elements, like the example below:_ - -```sh -$ node -> ["H", "e", "l", "l", "o"].join(); -'H,e,l,l,o' -> ["H", "e", "l", "l", "o"].join("--"); -'H--e--l--l--o' -``` - -There is a string method `.split()`. In an interactive console try using the string `.split()` method and the array `.join()`. How could they work together? diff --git a/week-2/Homework/L-array-methods-2/exercise.js b/week-2/Homework/L-array-methods-2/exercise.js deleted file mode 100644 index d36303b84..000000000 --- a/week-2/Homework/L-array-methods-2/exercise.js +++ /dev/null @@ -1,33 +0,0 @@ -/* - Array methods - .slice() - ------------------------ - The variable `firstFive` should contain the first five items of `everyone` - The variable `lastFive` should contain the last five items of `everyone` -*/ - -var everyone = [ - "Daniel", - "Irina", - "Rares", - "Rukmini", - "Abdul", - "Austine", - "Swathi" -]; - -var firstFive; // complete this statement -var lastFive; // complete this statement - -/* - DO NOT EDIT BELOW THIS LINE - --------------------------- */ - -console.log(firstFive); -console.log(lastFive); - -/* - EXPECTED RESULT - --------------- - ["Daniel", "Irina", "Rares", "Rukmini", "Abdul"] - ["Rares", "Rukmini", "Abdul", "Austine", "Swathi"] -*/ diff --git a/week-2/Homework/L-array-methods-2/exercise2.js b/week-2/Homework/L-array-methods-2/exercise2.js deleted file mode 100644 index b7be576e7..000000000 --- a/week-2/Homework/L-array-methods-2/exercise2.js +++ /dev/null @@ -1,25 +0,0 @@ -/* - Array methods - .join() - ------------------------- - Complete the capitalise function - It should return a string with the first letter in uppercase - For example, capitailise("hello") should return "Hello" - Tip: use the string method .split() and the array method .join() -*/ - -function capitalise(str) {} - -/* - DO NOT EDIT BELOW THIS LINE - --------------------------- */ -var name = "daniel"; - -console.log(capitalise(name)); -console.log(capitalise("hello")); - -/* - EXPECTED RESULT - --------------- - Daniel - Hello -*/ diff --git a/week-2/Homework/L-array-methods-2/exercise3.js b/week-2/Homework/L-array-methods-2/exercise3.js deleted file mode 100644 index 82e9dd8c8..000000000 --- a/week-2/Homework/L-array-methods-2/exercise3.js +++ /dev/null @@ -1,26 +0,0 @@ -/* - Array methods - .includes() - --------------------------- - Complete the function below to check if a country is in the UK -*/ - -var ukNations = ["Scotland", "Wales", "England", "Northern Ireland"]; - -function isInUK(country) { - return; // complete this statement -} - -/* - DO NOT EDIT BELOW THIS LINE - --------------------------- */ -console.log(isInUK("France")); -console.log(isInUK("Republic of Ireland")); -console.log(isInUK("England")); - -/* - EXPECTED RESULT - --------------- - false - false - true -*/ diff --git a/week-2/Homework/M-array-map/README.md b/week-2/Homework/M-array-map/README.md deleted file mode 100644 index 76ef865e2..000000000 --- a/week-2/Homework/M-array-map/README.md +++ /dev/null @@ -1,27 +0,0 @@ -Imagine you have an array of names... - -```js -var mentors = ["Daniel ", "irina ", " Gordon", "ashleigh "]; -``` - -You notice that he names are not formatted consistently. To fix the array you decide you need to trim whitespace and convert to lowercase. How do you do that for every value in the array? - -We can write a function that changes one name: - -```js -function tidy(name) { - return name.trim().toLowerCase(); -} -``` - -All you need to run every name in the array through this function and update the array values. Thankfully there is an array method that does just this! - -## `.map()` - -_Runs every item in the array through a function and returns a new array with the values returned by the function_. - -```js -var tidyMentors = mentors.map(tidy); - -console.log(tidyMentors); // logs ["daniel", "irina", "gordon", "ashleigh"] -``` diff --git a/week-2/Homework/M-array-map/exercise.js b/week-2/Homework/M-array-map/exercise.js deleted file mode 100644 index 783e8386c..000000000 --- a/week-2/Homework/M-array-map/exercise.js +++ /dev/null @@ -1,24 +0,0 @@ -/* - Array methods - .map() - ------------------------- - `numbersDoubled` should be an array containing all every value in `numbers` doubled - Use the .map() method to transform each item in the array -*/ - -function double(num) { - return num * 2; -} - -var numbers = [1, 2, 3, 4]; -var numbersDoubled; // complete this statement (use map and the double function) - -/* - DO NOT EDIT BELOW THIS LINE - --------------------------- */ -console.log(numbersDoubled); - -/* - EXPECTED RESULT - --------------- - [2,4,6,8] -*/