From 46d02d0c912d530c451dc70ac9ac784ba2e2ee85 Mon Sep 17 00:00:00 2001 From: Liam Greenfield <52577696+Liam310@users.noreply.github.com> Date: Mon, 13 Jul 2026 12:37:49 +0100 Subject: [PATCH 1/6] rename 0.js -> 400.js --- arrays/{0.js => 400.js} | 1 - 1 file changed, 1 deletion(-) rename arrays/{0.js => 400.js} (99%) diff --git a/arrays/0.js b/arrays/400.js similarity index 99% rename from arrays/0.js rename to arrays/400.js index 060d9d9c..6349b006 100644 --- a/arrays/0.js +++ b/arrays/400.js @@ -2,7 +2,6 @@ // Try predicting and explaining what will get logged to the console when the code runs // To check your prediction, play computer using the Python Visualiser: https://pythontutor.com/render.html#mode=display - const ingredients = ["olive oil","tomatoes",'garlic','onion', 'carrot']; let ingredientsCopy = ingredients; ingredientsCopy.push('pasta','salt','pepper'); From a98c30eacf67651f1b080a1bd3ab900f5d217d6e Mon Sep 17 00:00:00 2001 From: Liam Greenfield <52577696+Liam310@users.noreply.github.com> Date: Mon, 13 Jul 2026 12:38:53 +0100 Subject: [PATCH 2/6] correct task instructions --- arrays/100.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/arrays/100.js b/arrays/100.js index cdf2567d..19bf56c1 100644 --- a/arrays/100.js +++ b/arrays/100.js @@ -1,10 +1,9 @@ // Predict and explain... -// What will nums.length evalute to after running the code here -// Check your prediction and explanation by running the code. Use mdn documentation for mdn to help you make your prediction -// +// What will get logged to the console when running the code below? +// Check your prediction and explanation by running the code. Use the MDN documentation for .push to help build your understanding of these outcomes -const cities = ["Manchester", "London","Birmingham","Cape Town","Glasgow"]; -const result = cities.push("Liverpool","Sheffield"); +const cities = ["Manchester", "London", "Birmingham", "Cape Town", "Glasgow"]; +const result = cities.push("Liverpool", "Sheffield"); console.log(`The result is ${result}`); -console.log("cities now looks like this: ",cities); \ No newline at end of file +console.log("cities now looks like this: ", cities); From 82a835a74180d51932707df03413ac976305ae36 Mon Sep 17 00:00:00 2001 From: Liam Greenfield <52577696+Liam310@users.noreply.github.com> Date: Mon, 13 Jul 2026 12:39:14 +0100 Subject: [PATCH 3/6] fix formatting --- arrays/200.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arrays/200.js b/arrays/200.js index 134e8563..f5c336dd 100644 --- a/arrays/200.js +++ b/arrays/200.js @@ -1,8 +1,8 @@ // Predict and explain... -// What will nums.length evalute to after running the code here +// What will nums.length evaluate to after running the code here? // Check your prediction and explanation by running the code -const nums = [10,3,5,6,]; +const nums = [10, 3, 5, 6]; nums[6] = 50; From 68d790ef018fec96339bdd24907983090d28e0d4 Mon Sep 17 00:00:00 2001 From: Liam Greenfield <52577696+Liam310@users.noreply.github.com> Date: Mon, 13 Jul 2026 12:39:29 +0100 Subject: [PATCH 4/6] remove whitespace --- arrays/300.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arrays/300.js b/arrays/300.js index da825e08..ad162b33 100644 --- a/arrays/300.js +++ b/arrays/300.js @@ -1,7 +1,6 @@ // the head of an array is the first element of an array // the tail of an array is the last element of an array - const alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']; function getHead(arr) { @@ -15,5 +14,6 @@ function getTail(arr) { console.log(`The first letter of the alphabet is ${getHead(alphabet)}`); console.log(`The last letter of the alphabet is ${getTail(alphabet)}`); console.log(alphabet.length); + // Explain why alphabet length is now 24 // How could we change the functions we defined to return the same values, but not change the length of alphabet? From 547b2a0fd0b89d7d73a4456cf73de58a18ae243a Mon Sep 17 00:00:00 2001 From: Liam Greenfield <52577696+Liam310@users.noreply.github.com> Date: Mon, 13 Jul 2026 12:42:45 +0100 Subject: [PATCH 5/6] rename files to remove gaps in order all file names were decremented by 100 because no file prefixed with 500 previously existed --- arrays/500.test.js | 24 +++++++++++++++++++++++ arrays/600.test.js | 37 +++++++++++++---------------------- arrays/700.js | 21 ++++++++++++++++++++ arrays/700.test.js | 17 ---------------- arrays/800.js | 48 ++++++++++++++++++++++++++++++---------------- arrays/900.js | 37 ----------------------------------- 6 files changed, 90 insertions(+), 94 deletions(-) create mode 100644 arrays/500.test.js create mode 100644 arrays/700.js delete mode 100644 arrays/700.test.js delete mode 100644 arrays/900.js diff --git a/arrays/500.test.js b/arrays/500.test.js new file mode 100644 index 00000000..19a6b4d4 --- /dev/null +++ b/arrays/500.test.js @@ -0,0 +1,24 @@ +// list is an array that holds a mix of data types +// we need to collect just the numbers and not the strings +// before runnning the tests, make a prediction and explanation about what you expect the function to return +// fix anything that doesn't work + +function collectNumbers(list) { + const numbersOnly = []; + for (const item of list) { + if (item === 'string') { + numbersOnly.push(item); + } + } + return numbersOnly; +} + +// NOTE: you do not need to change anything in the test +test('only collects numbers in the array',() => { + const currentOutput = collectNumbers([10.1,"hello",6.1,8.0, 9.7, 10.1,"hi", 3.5,"oops"]); + const targetOutput = [10.1,6.1,8.0, 9.7, 10.1, 3.5,]; + + expect(currentOutput).toEqual(targetOutput); +}); + + diff --git a/arrays/600.test.js b/arrays/600.test.js index 4714a498..00c4c33c 100644 --- a/arrays/600.test.js +++ b/arrays/600.test.js @@ -1,26 +1,15 @@ - - -// list is an array that holds a mix of data types -// we need to collect just the numbers and not the strings -// before runnning the tests, make a prediction and explanation about what you expect the function to return -// fix anything that doesn't work - -function collectNumbers(list) { - - const numbersOnly = []; - for (const item of list) { - if (item === 'string') { - numbersOnly.push(item); - } - } - return numbersOnly; +// Predict and explain... +// Below is a function countWords and a test that checks that it counts the words in a string correctly +// At the moment, it isn't working. Try to reason about what happens when the function is called. +// Check your prediction and explanation using the test +// Fix anything that doesn't work + +function countWords(text) { + return text.split('').length; } -test('only collects numbers in the array',() => { - const currentOutput = collectNumbers([10.1,"hello",6.1,8.0, 9.7, 10.1,"hi", 3.5,"oops"]); - const targetOutput = [10.1,6.1,8.0, 9.7, 10.1, 3.5,]; - - expect(currentOutput).toEqual(targetOutput); -}); - - +// NOTE: you do not need to change anything in the test +test('should count the words in a string of text', () => { + const text = "Here is a plain sentence with some information! Try to find the word count"; + expect(countWords(text)).toBe(14); +}); \ No newline at end of file diff --git a/arrays/700.js b/arrays/700.js new file mode 100644 index 00000000..40472abd --- /dev/null +++ b/arrays/700.js @@ -0,0 +1,21 @@ +// Predict and explain... +// We've seen for..of loops used for arrays. +// Below we try to use it with a variable which isn't an array. +// What do you think will get logged? +// Don't run the code until you've predicted and explained the whole file. +// Then check your prediction and explanation by running the code + +const sentence = "I really enjoy ice cream"; + +for (const part of sentence) { + console.log(part); +} + +// What's the difference between what was written above, and what's below? +// How will they behave differently? + +const parts = sentence.split(" "); + +for (const part of parts) { + console.log(part); +} diff --git a/arrays/700.test.js b/arrays/700.test.js deleted file mode 100644 index 049e9baa..00000000 --- a/arrays/700.test.js +++ /dev/null @@ -1,17 +0,0 @@ -// Predict and explain... -// Below is a function countWords and a test that checks that it counts the words in a string correctly -// At the moment, it isn't working. Try to reason about what happens when the function is called. -// Check your prediction and explanation using the tests -// Fix anything that doesn't work - -function countWords(text) { - return text.split('').length; -} - - -test('should count the words in a string of text', () => { - - const text = "Here is a plain sentence with some information! Try to find the word count"; - expect(countWords(text)).toBe(14); - -}); \ No newline at end of file diff --git a/arrays/800.js b/arrays/800.js index 40472abd..de9c9826 100644 --- a/arrays/800.js +++ b/arrays/800.js @@ -1,21 +1,37 @@ -// Predict and explain... -// We've seen for..of loops used for arrays. -// Below we try to use it with a variable which isn't an array. -// What do you think will get logged? -// Don't run the code until you've predicted and explained the whole file. -// Then check your prediction and explanation by running the code +// Below, we have two functions which have the same aim. +// Both functions take a word as a parameter. +// If the function has been called with that word before (regardless of case), the previous version of the word is returned. +// So if you called the function with "hello", then "HELLO", the second call will return "hello". +// If the word has not been used before, it will just be returned as-is. -const sentence = "I really enjoy ice cream"; +// One of these functions has side-effects. +// When you call it, it does something other than just returning a value based only on its parameters. +// +// The other doesn't have side effects. +// When you call it with the same arguments, it always does exactly the same thing, +// and you can see everything it does in its return value. +// +// Which function has side-effects? Which doesn't? +// Try to write tests for both functions. +// Which was easier to test? What issues did you run into writing tests? -for (const part of sentence) { - console.log(part); -} - -// What's the difference between what was written above, and what's below? -// How will they behave differently? +const previousWords = []; -const parts = sentence.split(" "); +function getPreviousCaseOfWordOne(word) { + for (const previousWord of previousWords) { + if (previousWord.toLowerCase() === word.toLowerCase()) { + return previousWord; + } + } + previousWords.push(word); + return word; +} -for (const part of parts) { - console.log(part); +function getPreviousCaseOfWordTwo(word, words) { + for (const previousWord of words) { + if (previousWord.toLowerCase() === word.toLowerCase()) { + return previousWord; + } + } + return word; } diff --git a/arrays/900.js b/arrays/900.js deleted file mode 100644 index de9c9826..00000000 --- a/arrays/900.js +++ /dev/null @@ -1,37 +0,0 @@ -// Below, we have two functions which have the same aim. -// Both functions take a word as a parameter. -// If the function has been called with that word before (regardless of case), the previous version of the word is returned. -// So if you called the function with "hello", then "HELLO", the second call will return "hello". -// If the word has not been used before, it will just be returned as-is. - -// One of these functions has side-effects. -// When you call it, it does something other than just returning a value based only on its parameters. -// -// The other doesn't have side effects. -// When you call it with the same arguments, it always does exactly the same thing, -// and you can see everything it does in its return value. -// -// Which function has side-effects? Which doesn't? -// Try to write tests for both functions. -// Which was easier to test? What issues did you run into writing tests? - -const previousWords = []; - -function getPreviousCaseOfWordOne(word) { - for (const previousWord of previousWords) { - if (previousWord.toLowerCase() === word.toLowerCase()) { - return previousWord; - } - } - previousWords.push(word); - return word; -} - -function getPreviousCaseOfWordTwo(word, words) { - for (const previousWord of words) { - if (previousWord.toLowerCase() === word.toLowerCase()) { - return previousWord; - } - } - return word; -} From c8c33037c87063d26c6fb8a08865fd6cb7242874 Mon Sep 17 00:00:00 2001 From: Liam Greenfield <52577696+Liam310@users.noreply.github.com> Date: Mon, 13 Jul 2026 12:48:18 +0100 Subject: [PATCH 6/6] fix typo --- arrays/500.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arrays/500.test.js b/arrays/500.test.js index 19a6b4d4..43ea57dc 100644 --- a/arrays/500.test.js +++ b/arrays/500.test.js @@ -1,6 +1,6 @@ // list is an array that holds a mix of data types // we need to collect just the numbers and not the strings -// before runnning the tests, make a prediction and explanation about what you expect the function to return +// before running the tests, make a prediction and explanation about what you expect the function to return // fix anything that doesn't work function collectNumbers(list) {