Skip to content

Sprint 3 alarmclock #502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
9 changes: 7 additions & 2 deletions Sprint-1/fix/median.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@

function calculateMedian(list) {
const middleIndex = Math.floor(list.length / 2);
const median = list.splice(middleIndex, 1)[0];
return median;

if (list.length % 2 === 0) {
const median = (list[middleIndex-1] + list[middleIndex]) /2;
return median;
} else {
return list[middleIndex];
}
}

module.exports = calculateMedian;
12 changes: 11 additions & 1 deletion Sprint-1/implement/dedupe.js
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
function dedupe() {}
function dedupe(arr) {
const modified = [];

arr.forEach(el => {
if (!modified.includes(el)) {
modified.push(el) ;
}
})
return modified;
}
module.exports = dedupe;
34 changes: 24 additions & 10 deletions Sprint-1/implement/dedupe.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,29 @@ E.g. dedupe([1, 2, 1]) target output: [1, 2]

// Acceptance Criteria:

// Given an empty array
// When passed to the dedupe function
// Then it should return an empty array
test.todo("given an empty array, it returns an empty array");
describe("dedupe", () => {
test("given an empty array, it returns an empty array", () => {
// Given an empty array
// When passed to the dedupe function
// Then it should return an empty array
expect(dedupe([])).toEqual([]);
});

// Given an array with no duplicates
// When passed to the dedupe function
// Then it should return a copy of the original array
// Given an array with no duplicates
// When passed to the dedupe function
// Then it should return a copy of the original array
test("given an array with no duplicates, it returns a copy of the original array", () => {
const array = [1, 2, 3];
const result = dedupe(array);
expect(result).toEqual([1, 2, 3]);
});

// Given an array with strings or numbers
// When passed to the dedupe function
// Then it should remove the duplicate values, preserving the first occurence of each element
// Given an array with strings or numbers
// When passed to the dedupe function
// Then it should remove the duplicate values, preserving the first occurrence of each element
test("given an array with strings or numbers, it removes duplicate values and keeps one of each element", () => {
const array = [1, 1, 2, 3];
const result = dedupe(array);
expect(result).toEqual([1, 2, 3]);
});
});
17 changes: 16 additions & 1 deletion Sprint-1/implement/max.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
function findMax(elements) {
}
// inf includes non-numerical and numberical
//ignore non numerical
let filtered = elements.filter(element => typeof element === 'number')

//check if empty
if (filtered.length === 0) {
return -Infinity;
} else if (filtered.length === 1) {
return filtered[0]
} else {
//find max
return Math.max(...filtered)
}

}


module.exports = findMax;
53 changes: 42 additions & 11 deletions Sprint-1/implement/max.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,63 @@ We have set things up already so that this file can see your function from the o

const findMax = require("./max.js");

// Given an empty array
// When passed to the max function
// Then it should return -Infinity
// Delete this test.todo and replace it with a test.
test.todo("given an empty array, returns -Infinity");
describe('find max', () => {
// Given an empty array
// When passed to the max function
// Then it should return -Infinity
test('given an empty array, it returns -Infinity', () => {
expect(findMax([])).toEqual(-Infinity);
});

// Given an array with one number
// When passed to the max function
// Then it should return that number

// Given an array with both positive and negative numbers
test('given an array with one number, it returns that number', () => {
expect(findMax([1])).toEqual(1)
});
// // Given an array with both positive and negative numbers
// When passed to the max function
// Then it should return the largest number overall

test('given an array with positive and negative integers, it returns the largest number overall', () => {
expect(findMax([-1, 1])).toEqual(1)
})
// Given an array with just negative numbers
// When passed to the max function
// Then it should return the closest one to zero

test('given an array of negative integers, it returns the closes one to 0', () => {
expect(findMax([-2,-1])).toEqual(-1)
})
// Given an array with decimal numbers
// When passed to the max function
// Then it should return the largest decimal number
test('given an array with decimal numbers, it returns the largest decimal number', () => {
expect(findMax([0.97, 0.48, 0.2])).toEqual(0.97)
})


// Given an array with non-number values
// When passed to the max function
// Then it should return the max and ignore non-numeric values
test('given an array with non-number values, it returns the max and ignore non-numbers', () => {
expect(findMax(['cat', 1, 5])).toEqual(5)
})

// Given an array with only non-number values


// Given an array with non-number values
// When passed to the max function
// Then it should return the least surprising value given how it behaves for all other inputs
// Then it should return the max and ignore non-numeric values
test('given an array with non-number values, it returns the max and ignore non-numbers', () => {
expect(findMax(['cat', 1, 5])).toEqual(5)
})
});










5 changes: 4 additions & 1 deletion Sprint-2/debug/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ const address = {
postcode: "XYZ 123",
};

console.log(`My house number is ${address[0]}`);
// console.log(`My house number is ${address[0]}`);
console.log(`My house number is ${address.houseNumber}`);

//address 0 points to houseNumber, not number 42.
9 changes: 7 additions & 2 deletions Sprint-2/debug/author.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ const author = {
alive: true,
};

for (const value of author) {
console.log(value);
// for (const value of author) {
// console.log(value);
// }
for (const value in author) {
console.log(value, author[value]);
}

// it attempts to loop over the object author and log the values of all properties
7 changes: 5 additions & 2 deletions Sprint-2/debug/recipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
// Each ingredient should be logged on a new line
// How can you fix it?

//To correctly log out the title, it should point to recipe.ingredients

const recipe = {
title: "bruschetta",
serves: 2,
ingredients: ["olive oil", "tomatoes", "salt", "pepper"],
};

console.log(`${recipe.title} serves ${recipe.serves}
ingredients:
${recipe}`);
ingredients: `)

recipe.ingredients.forEach(ingredient => console.log(ingredient))
18 changes: 17 additions & 1 deletion Sprint-2/implement/contains.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
function contains() {}
const contains = (object, prop) => {
// check if the object is empty
const isEmpty = (object) => {
return Object.keys(object).length === 0;
}

if (isEmpty(object)) {
return false;
}

if (object.hasOwnProperty(prop)) {
return true;
} else {
return false;
}
};


module.exports = contains;
26 changes: 23 additions & 3 deletions Sprint-2/implement/contains.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,44 @@ as the object doesn't contains a key of 'c'
*/

// Acceptance criteria:

// Given a contains function
describe('check props', () => {
const cat = {
name: 'Laser',
legs: 4,
color: 'grey',
};
// Given a contains function
// When passed an object and a property name
// Then it should return true if the object contains the property, false otherwise
test('given passed object and prop name, it returns true if contains the property, false if not', () => {
expect(contains(cat, 'name')).toEqual(true)
})

// Given an empty object
// When passed to contains
// Then it should return false
test.todo("contains on empty object returns false");
test('contains on empty object returns false', () => {
expect(contains({})).toEqual(false)
})

// Given an object with properties
// When passed to contains with an existing property name
// Then it should return true
test('contains an object with existing peoperty returns true', () => {
expect(contains(cat, 'color')).toEqual(true)
})

// Given an object with properties
// When passed to contains with a non-existent property name
// Then it should return false
test('contains an object with properties, non existent property name returns false', () => {
expect(contains(cat, 'age')).toEqual(false)
})

// Given invalid parameters like an array
// When passed to contains
// Then it should return false or throw an error
test('given invalid parameters, it returns false', () => {
expect(contains([])).toEqual(false)
})
})
23 changes: 21 additions & 2 deletions Sprint-2/implement/lookup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
function createLookup() {
// implementation here


function createLookup(array) {
let object = {};

array.forEach(([country, currency]) => {
object[country] = currency;
});

return object;
}


// function sortCats(cats) {
// let kitty = {};

// cats.forEach(([catNameKey, catNameValue, age]) => {
// kitty[catNameKey] = catNameValue;
// kitty[age] = parseInt(age);
// })
// return kitty
// }
module.exports = createLookup;

39 changes: 8 additions & 31 deletions Sprint-2/implement/lookup.test.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,12 @@
const createLookup = require("./lookup.js");

test.todo("creates a country currency code lookup for multiple codes");
describe('creates a country currency code lookup for multiple codes', () => {
const countryCurrencyPairs = [['US', 'USD'], ['CA', 'CAD']];

/*

Create a lookup object of key value pairs from an array of code pairs

Acceptance Criteria:

Given
- An array of arrays representing country code and currency code pairs
e.g. [['US', 'USD'], ['CA', 'CAD']]

When
- createLookup function is called with the country-currency array as an argument

Then
- It should return an object where:
- The keys are the country codes
- The values are the corresponding currency codes

Example
Given: [['US', 'USD'], ['CA', 'CAD']]

When
createLookup(countryCurrencyPairs) is called

Then
It should return:
{
'US': 'USD',
'CA': 'CAD'
}
*/
test('when called with country-currency array, it returns an object with country: currency', () => {
expect(createLookup(countryCurrencyPairs)).toEqual({
'US': 'USD',
'CA': 'CAD'
});
})})
Loading