Skip to content
This repository was archived by the owner on Jul 22, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions arrays/100.js
Original file line number Diff line number Diff line change
@@ -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);
console.log("cities now looks like this: ", cities);
4 changes: 2 additions & 2 deletions arrays/200.js
Original file line number Diff line number Diff line change
@@ -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];

@Liam310 Liam310 Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debated whether to remove this trailing comma, but decided that its presence didn't contribute anything meaningful to the task which is ultimately about understanding how JS handles empty items of an array.

(if there were two trailing commas then that would have in impact on the array at the point of its initial declaration, but one has no effect)


nums[6] = 50;

Expand Down
2 changes: 1 addition & 1 deletion arrays/300.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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?
1 change: 0 additions & 1 deletion arrays/0.js → arrays/400.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
24 changes: 24 additions & 0 deletions arrays/500.test.js
Original file line number Diff line number Diff line change
@@ -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 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) {
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);
});


37 changes: 13 additions & 24 deletions arrays/600.test.js
Original file line number Diff line number Diff line change
@@ -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);
});
21 changes: 21 additions & 0 deletions arrays/700.js
Original file line number Diff line number Diff line change
@@ -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);
}
17 changes: 0 additions & 17 deletions arrays/700.test.js

This file was deleted.

48 changes: 32 additions & 16 deletions arrays/800.js
Original file line number Diff line number Diff line change
@@ -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;
}
37 changes: 0 additions & 37 deletions arrays/900.js

This file was deleted.