From bed2c08a6d12f0fb39223ccfc3f0abfc2a44e787 Mon Sep 17 00:00:00 2001 From: AJ Lobb Date: Mon, 28 Feb 2022 13:52:24 +0000 Subject: [PATCH 01/22] typed in the number text --- src/__tests__/numbers.test.js | 18 +++++++++--------- src/numbers.js | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/__tests__/numbers.test.js b/src/__tests__/numbers.test.js index 1cb4961..468413f 100644 --- a/src/__tests__/numbers.test.js +++ b/src/__tests__/numbers.test.js @@ -11,7 +11,7 @@ const { } = require('../numbers'); describe('add', () => { - xit('adds the two numbers together', () => { + it('adds the two numbers together', () => { expect(add(2, 1)).toEqual(3); expect(add(15, 76)).toEqual(91); expect(add(12, 0)).toEqual(12); @@ -20,7 +20,7 @@ describe('add', () => { }); describe('subtract', () => { - xit('subtracts the second number from the first', () => { + it('subtracts the second number from the first', () => { expect(subtract(2, 1)).toEqual(1); expect(subtract(1, 2)).toEqual(-1); expect(subtract(-2, 1)).toEqual(-3); @@ -30,7 +30,7 @@ describe('subtract', () => { }); describe('multiply', () => { - xit('multiplies the two numbers together', () => { + it('multiplies the two numbers together', () => { expect(multiply(10, 3)).toEqual(30); expect(multiply(-11, 5)).toEqual(-55); expect(multiply(-4, -9)).toEqual(36); @@ -38,7 +38,7 @@ describe('multiply', () => { }); describe('divide', () => { - xit('divides the first number by the second number', () => { + it('divides the first number by the second number', () => { expect(divide(20, 5)).toEqual(4); expect(divide(5, 2)).toEqual(2.5); expect(divide(2, 5)).toEqual(0.4); @@ -47,7 +47,7 @@ describe('divide', () => { }); describe('power', () => { - xit('returns the first number to the power of the second', () => { + it('returns the first number to the power of the second', () => { expect(power(5, 2)).toEqual(25); expect(power(2, 3)).toEqual(8); expect(power(10, 5)).toEqual(100000); @@ -55,7 +55,7 @@ describe('power', () => { }); describe('round', () => { - xit('rounds the number to the nearest integer', () => { + it('rounds the number to the nearest integer', () => { expect(round(2.1)).toEqual(2); expect(round(9.7)).toEqual(10); expect(round(5.5)).toEqual(6); @@ -63,7 +63,7 @@ describe('round', () => { }); describe('roundUp', () => { - xit('rounds the number up to the nearest integer', () => { + it('rounds the number up to the nearest integer', () => { expect(roundUp(2.1)).toEqual(3); expect(roundUp(9.7)).toEqual(10); expect(roundUp(5.5)).toEqual(6); @@ -71,7 +71,7 @@ describe('roundUp', () => { }); describe('roundDown', () => { - xit('rounds the number down to the nearest integer', () => { + it('rounds the number down to the nearest integer', () => { expect(roundDown(2.1)).toEqual(2); expect(roundDown(9.7)).toEqual(9); expect(roundDown(5.5)).toEqual(5); @@ -79,7 +79,7 @@ describe('roundDown', () => { }); describe('absolute', () => { - xit('returns the absolute value of the number', () => { + it('returns the absolute value of the number', () => { expect(absolute(-1)).toEqual(1); expect(absolute(1)).toEqual(1); expect(absolute(0)).toEqual(0); diff --git a/src/numbers.js b/src/numbers.js index 9d192c9..804e1c3 100644 --- a/src/numbers.js +++ b/src/numbers.js @@ -1,37 +1,37 @@ function add (a, b) { - // your code here + return a+b } function subtract (a, b) { - // your code here + return a - b } function multiply (a, b) { - // your code here + return a * b } function divide (a, b) { - // your code here + return a / b } function power (a, b) { - // your code here + return Math.pow(a, b) } function round (a) { - // your code here + return Math.round(a) } function roundUp (a) { - // your code here + return Math.ceil(a) } function roundDown (a) { - // your code here + return Math.floor(a) } function absolute (a) { - // your code here + return Math.abs(a) } module.exports = { From 761d2ca2b74c20785e35aa8ee8ddf8064e1b7c60 Mon Sep 17 00:00:00 2001 From: AJ Lobb Date: Mon, 28 Feb 2022 13:54:30 +0000 Subject: [PATCH 02/22] Tests passed. Adding X infront of it --- src/__tests__/numbers.test.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/__tests__/numbers.test.js b/src/__tests__/numbers.test.js index 468413f..1cb4961 100644 --- a/src/__tests__/numbers.test.js +++ b/src/__tests__/numbers.test.js @@ -11,7 +11,7 @@ const { } = require('../numbers'); describe('add', () => { - it('adds the two numbers together', () => { + xit('adds the two numbers together', () => { expect(add(2, 1)).toEqual(3); expect(add(15, 76)).toEqual(91); expect(add(12, 0)).toEqual(12); @@ -20,7 +20,7 @@ describe('add', () => { }); describe('subtract', () => { - it('subtracts the second number from the first', () => { + xit('subtracts the second number from the first', () => { expect(subtract(2, 1)).toEqual(1); expect(subtract(1, 2)).toEqual(-1); expect(subtract(-2, 1)).toEqual(-3); @@ -30,7 +30,7 @@ describe('subtract', () => { }); describe('multiply', () => { - it('multiplies the two numbers together', () => { + xit('multiplies the two numbers together', () => { expect(multiply(10, 3)).toEqual(30); expect(multiply(-11, 5)).toEqual(-55); expect(multiply(-4, -9)).toEqual(36); @@ -38,7 +38,7 @@ describe('multiply', () => { }); describe('divide', () => { - it('divides the first number by the second number', () => { + xit('divides the first number by the second number', () => { expect(divide(20, 5)).toEqual(4); expect(divide(5, 2)).toEqual(2.5); expect(divide(2, 5)).toEqual(0.4); @@ -47,7 +47,7 @@ describe('divide', () => { }); describe('power', () => { - it('returns the first number to the power of the second', () => { + xit('returns the first number to the power of the second', () => { expect(power(5, 2)).toEqual(25); expect(power(2, 3)).toEqual(8); expect(power(10, 5)).toEqual(100000); @@ -55,7 +55,7 @@ describe('power', () => { }); describe('round', () => { - it('rounds the number to the nearest integer', () => { + xit('rounds the number to the nearest integer', () => { expect(round(2.1)).toEqual(2); expect(round(9.7)).toEqual(10); expect(round(5.5)).toEqual(6); @@ -63,7 +63,7 @@ describe('round', () => { }); describe('roundUp', () => { - it('rounds the number up to the nearest integer', () => { + xit('rounds the number up to the nearest integer', () => { expect(roundUp(2.1)).toEqual(3); expect(roundUp(9.7)).toEqual(10); expect(roundUp(5.5)).toEqual(6); @@ -71,7 +71,7 @@ describe('roundUp', () => { }); describe('roundDown', () => { - it('rounds the number down to the nearest integer', () => { + xit('rounds the number down to the nearest integer', () => { expect(roundDown(2.1)).toEqual(2); expect(roundDown(9.7)).toEqual(9); expect(roundDown(5.5)).toEqual(5); @@ -79,7 +79,7 @@ describe('roundDown', () => { }); describe('absolute', () => { - it('returns the absolute value of the number', () => { + xit('returns the absolute value of the number', () => { expect(absolute(-1)).toEqual(1); expect(absolute(1)).toEqual(1); expect(absolute(0)).toEqual(0); From f298ef3ca22312a4e0cf5e9aaa40b98e5f4c9591 Mon Sep 17 00:00:00 2001 From: WhyAtS <79106648+WhyAtS@users.noreply.github.com> Date: Mon, 28 Feb 2022 14:07:31 +0000 Subject: [PATCH 03/22] strings completed --- src/__tests__/strings.test.js | 18 +++++++++--------- src/strings.js | 24 ++++++++++++------------ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/__tests__/strings.test.js b/src/__tests__/strings.test.js index e2c3c88..b19fd73 100644 --- a/src/__tests__/strings.test.js +++ b/src/__tests__/strings.test.js @@ -8,21 +8,21 @@ const { } = require('../strings'); describe('sayHello', () => { - xit('returns "Hello world!" when passed "world"', () => { + it('returns "Hello world!" when passed "world"', () => { expect(sayHello('world')).toEqual('Hello, world!'); }); - xit('returns "Hello MCR Codes!" when passed "MCR Codes"', () => { + it('returns "Hello MCR Codes!" when passed "MCR Codes"', () => { expect(sayHello('MCR Codes')).toEqual('Hello, MCR Codes!'); }); - xit('returns "Hello fsghjdfkhgf!" when passed "fsghjdfkhgf"', () => { + it('returns "Hello fsghjdfkhgf!" when passed "fsghjdfkhgf"', () => { expect(sayHello('fsghjdfkhgf')).toEqual('Hello, fsghjdfkhgf!'); }); }); describe('uppercase', () => { - xit('returns the uppercased string', () => { + it('returns the uppercased string', () => { expect(uppercase('abc')).toEqual('ABC'); expect(uppercase('def')).toEqual('DEF'); expect(uppercase('ghi')).toEqual('GHI'); @@ -30,7 +30,7 @@ describe('uppercase', () => { }); describe('lowercase', () => { - xit('returns the lowercased string', () => { + it('returns the lowercased string', () => { expect(lowercase('ABC')).toEqual('abc'); expect(lowercase('DEF')).toEqual('def'); expect(lowercase('GHI')).toEqual('ghi'); @@ -38,7 +38,7 @@ describe('lowercase', () => { }); describe('countCharacters', () => { - xit('returns the number of characters in the string', () => { + it('returns the number of characters in the string', () => { expect(countCharacters('fsfsgsfdg')).toEqual(9); expect(countCharacters('fsfsg')).toEqual(5); expect(countCharacters('')).toEqual(0); @@ -46,7 +46,7 @@ describe('countCharacters', () => { }); describe('firstCharacter', () => { - xit('returns the first character of the string', () => { + it('returns the first character of the string', () => { expect(firstCharacter('ABC')).toEqual('A'); expect(firstCharacter('DEF')).toEqual('D'); expect(firstCharacter('GHI')).toEqual('G'); @@ -54,11 +54,11 @@ describe('firstCharacter', () => { }); describe('firstCharacters', () => { - xit('returns the first 4 characters of the string', () => { + it('returns the first 4 characters of the string', () => { expect(firstCharacters('sd32fg45', 4)).toEqual('sd32'); }); - xit('returns the first 2 characters of the string', () => { + it('returns the first 2 characters of the string', () => { expect(firstCharacters('asd', 2)).toEqual('as'); }); }); diff --git a/src/strings.js b/src/strings.js index ce02aff..78ca395 100644 --- a/src/strings.js +++ b/src/strings.js @@ -1,25 +1,25 @@ -function sayHello (string) { - // your code here +function sayHello(string) { + return "Hello, " + string + "!" }; -function uppercase (string) { - // your code here +function uppercase(string) { + return string.toUpperCase() }; -function lowercase (string) { - // your code here +function lowercase(string) { + return string.toLowerCase() }; -function countCharacters (string) { - // your code here +function countCharacters(string) { + return string.length }; -function firstCharacter (string) { - // your code here +function firstCharacter(string) { + return string[0] }; -function firstCharacters (string, n) { - // your code here +function firstCharacters(string, n) { + return string.substring(0,n) }; module.exports = { From d2b2abd66b0889f8da55ecbfe1adb939062b5c8a Mon Sep 17 00:00:00 2001 From: AJ Lobb Date: Mon, 28 Feb 2022 14:09:20 +0000 Subject: [PATCH 04/22] first three passes on Objects --- src/__tests__/objects.test.js | 20 ++++++++++---------- src/objects.js | 28 +++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/__tests__/objects.test.js b/src/__tests__/objects.test.js index 77abc37..1755397 100644 --- a/src/__tests__/objects.test.js +++ b/src/__tests__/objects.test.js @@ -12,7 +12,7 @@ const { } = require('../objects'); describe('createPerson', () => { - xit('creates an object with the given name and age properties', () => { + it('creates an object with the given name and age properties', () => { expect(createPerson('Fred', 79)).toEqual({ name: 'Fred', age: 79 @@ -26,7 +26,7 @@ describe('createPerson', () => { }); describe('getName', () => { - xit('returns the name property of the object', () => { + it('returns the name property of the object', () => { expect( getName({ name: 'Fred', @@ -43,7 +43,7 @@ describe('getName', () => { }); describe('getProperty', () => { - xit('returns the given property', () => { + it('returns the given property', () => { expect( getProperty('age', { name: 'Fred', @@ -70,7 +70,7 @@ describe('hasProperty', () => { age: 23 }; - xit('returns true if the object has the given property', () => { + it('returns true if the object has the given property', () => { expect(hasProperty('age', fred)).toBe(true); expect(hasProperty('name', tom)).toBe(true); expect(hasProperty('favouriteColour', fred)).toBe(false); @@ -79,7 +79,7 @@ describe('hasProperty', () => { }); describe('isOver65', () => { - xit('returns true if the person is aged over 65', () => { + it('returns true if the person is aged over 65', () => { const jim = { name: 'Jim', age: 66 @@ -102,7 +102,7 @@ describe('isOver65', () => { }); describe('getAges', () => { - xit('returns the ages of each person in the array', () => { + it('returns the ages of each person in the array', () => { const jim = { name: 'Jim', age: 66 @@ -125,7 +125,7 @@ describe('getAges', () => { }); describe('findByName', () => { - xit('returns the person with the given name', () => { + it('returns the person with the given name', () => { const jim = { name: 'Jim', age: 66 @@ -147,7 +147,7 @@ describe('findByName', () => { }); describe('findHondas', () => { - xit('returns a list of cars manufactured by Honda', () => { + it('returns a list of cars manufactured by Honda', () => { const car1 = { manufacturer: 'Honda', year: 1997, @@ -179,7 +179,7 @@ describe('findHondas', () => { }); describe('averageAge', () => { - xit('returns the average age of the people in the list', () => { + it('returns the average age of the people in the list', () => { const john = { name: 'John', age: 60 @@ -207,7 +207,7 @@ describe('averageAge', () => { }); describe('createTalkingPerson', () => { - xit('returns a person who can introduce themselves', () => { + it('returns a person who can introduce themselves', () => { const bill = createTalkingPerson('Bill', 40); const catherine = createTalkingPerson('Catherine', 21); expect(bill).toEqual({ diff --git a/src/objects.js b/src/objects.js index 906eef8..e8027ec 100644 --- a/src/objects.js +++ b/src/objects.js @@ -1,21 +1,39 @@ const createPerson = (name, age) => { - // your code here + const person = { + name: name, + age: age, + } + return person }; const getName = object => { - // your code here + return object.name }; const getProperty = (property, object) => { - // your code here + if(property == "name"){ + return object.name + } else if (property == "age"){ + return object.age + } }; const hasProperty = (property, object) => { - // your code here + if(property == "name"){ + return true + } else if (property == "age"){ + return true + } else { + return false + } }; const isOver65 = person => { - // your code here + if (person.age < 65){ + return true + } else { + return false + } }; const getAges = people => { From 91c5bb6d021a43b2dc30881f6b8210b59a83c68c Mon Sep 17 00:00:00 2001 From: AJ Lobb Date: Mon, 28 Feb 2022 14:11:39 +0000 Subject: [PATCH 05/22] test for over 65 working --- src/objects.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/objects.js b/src/objects.js index e8027ec..5f28403 100644 --- a/src/objects.js +++ b/src/objects.js @@ -29,7 +29,7 @@ const hasProperty = (property, object) => { }; const isOver65 = person => { - if (person.age < 65){ + if (person.age > 65){ return true } else { return false From 3ceecdf6b9fb8a219b562cfb1c5f68a7a516f0be Mon Sep 17 00:00:00 2001 From: AJ Lobb Date: Mon, 28 Feb 2022 14:16:09 +0000 Subject: [PATCH 06/22] test passed for ages --- src/objects.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/objects.js b/src/objects.js index 5f28403..7c14a99 100644 --- a/src/objects.js +++ b/src/objects.js @@ -37,7 +37,13 @@ const isOver65 = person => { }; const getAges = people => { - // your code here + let output = [] + for (i = 0; i < people.length; i++){ + const person = people[i] + const age = person.age + output.push(age) + } + return output }; const findByName = (name, people) => { From 0f56e5982aa98afd55058f51bc4aaf0da1ebb8d7 Mon Sep 17 00:00:00 2001 From: Wes <76014409+Redtigercod4@users.noreply.github.com> Date: Mon, 28 Feb 2022 14:19:53 +0000 Subject: [PATCH 07/22] Classes JS complete --- src/__tests__/class.test.js | 18 +++++++++--------- src/class.js | 12 ++++++------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/__tests__/class.test.js b/src/__tests__/class.test.js index 64fc057..7fdc1d3 100644 --- a/src/__tests__/class.test.js +++ b/src/__tests__/class.test.js @@ -3,24 +3,24 @@ const { } = require('../class'); describe('sayHello', () => { - xit('returns "Hello world!" when passed "world"', () => { + it('returns "Hello world!" when passed "world"', () => { const obj = new testingClass('world'); expect(obj.sayHello()).toEqual('Hello, world!'); }); - xit('returns "Hello MCR Codes!" when passed "MCR Codes"', () => { + it('returns "Hello MCR Codes!" when passed "MCR Codes"', () => { const obj = new testingClass('MCR Codes'); expect(obj.sayHello()).toEqual('Hello, MCR Codes!'); }); - xit('returns "Hello fsghjdfkhgf!" when passed "fsghjdfkhgf"', () => { + it('returns "Hello fsghjdfkhgf!" when passed "fsghjdfkhgf"', () => { const obj = new testingClass('fsghjdfkhgf'); expect(obj.sayHello()).toEqual('Hello, fsghjdfkhgf!'); }); }); describe('uppercase', () => { - xit('returns the uppercased string', () => { + it('returns the uppercased string', () => { const obj1 = new testingClass('abc'); expect(obj1.uppercase()).toEqual('ABC'); const obj2 = new testingClass('def'); @@ -31,7 +31,7 @@ describe('uppercase', () => { }); describe('lowercase', () => { - xit('returns the lowercased string', () => { + it('returns the lowercased string', () => { const obj1 = new testingClass('ABC'); expect(obj1.lowercase()).toEqual('abc'); const obj2 = new testingClass('dEf'); @@ -42,7 +42,7 @@ describe('lowercase', () => { }); describe('countCharacters', () => { - xit('returns the number of characters in the string', () => { + it('returns the number of characters in the string', () => { const obj1 = new testingClass('fsfsgsfdg'); const obj2 = new testingClass('fsfsg'); const obj3 = new testingClass(''); @@ -54,7 +54,7 @@ describe('countCharacters', () => { }); describe('firstCharacter', () => { - xit('returns the first character of the string', () => { + it('returns the first character of the string', () => { const obj1 = new testingClass('ABC'); const obj2 = new testingClass('dEf'); const obj3 = new testingClass('GHi'); @@ -65,13 +65,13 @@ describe('firstCharacter', () => { }); describe('firstCharacters', () => { - xit('returns the first 4 characters of the string', () => { + it('returns the first 4 characters of the string', () => { const obj1 = new testingClass('sd32fg45'); expect(obj1.firstCharacters(4)).toEqual('sd32'); expect(obj1.firstCharacters(2)).toEqual('sd'); }); - xit('returns the first 2 characters of the string', () => { + it('returns the first 2 characters of the string', () => { const obj1 = new testingClass('asd'); expect(obj1.firstCharacters(2)).toEqual('as'); }); diff --git a/src/class.js b/src/class.js index 70d541b..7eadf5d 100644 --- a/src/class.js +++ b/src/class.js @@ -3,27 +3,27 @@ class testingClass { this._string = string; } sayHello = () => { - // your code here + return `Hello, ${this._string}!` }; uppercase = () => { - // your code here + return this._string.toUpperCase() }; lowercase = () => { - // your code here + return this._string.toLowerCase() }; countCharacters = () => { - // your code here + return this._string.length }; firstCharacter = () => { - // your code here + return this._string.charAt(0) }; firstCharacters = (n) => { - // your code here + return this._string.substr(0, n) }; } From 0e28981a03db868c906d98c7311a79d4b4b43a6a Mon Sep 17 00:00:00 2001 From: Wes <76014409+Redtigercod4@users.noreply.github.com> Date: Mon, 28 Feb 2022 14:22:44 +0000 Subject: [PATCH 08/22] Strings JS complete --- src/__tests__/strings.test.js | 18 +++++++++--------- src/strings.js | 12 ++++++------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/__tests__/strings.test.js b/src/__tests__/strings.test.js index e2c3c88..b19fd73 100644 --- a/src/__tests__/strings.test.js +++ b/src/__tests__/strings.test.js @@ -8,21 +8,21 @@ const { } = require('../strings'); describe('sayHello', () => { - xit('returns "Hello world!" when passed "world"', () => { + it('returns "Hello world!" when passed "world"', () => { expect(sayHello('world')).toEqual('Hello, world!'); }); - xit('returns "Hello MCR Codes!" when passed "MCR Codes"', () => { + it('returns "Hello MCR Codes!" when passed "MCR Codes"', () => { expect(sayHello('MCR Codes')).toEqual('Hello, MCR Codes!'); }); - xit('returns "Hello fsghjdfkhgf!" when passed "fsghjdfkhgf"', () => { + it('returns "Hello fsghjdfkhgf!" when passed "fsghjdfkhgf"', () => { expect(sayHello('fsghjdfkhgf')).toEqual('Hello, fsghjdfkhgf!'); }); }); describe('uppercase', () => { - xit('returns the uppercased string', () => { + it('returns the uppercased string', () => { expect(uppercase('abc')).toEqual('ABC'); expect(uppercase('def')).toEqual('DEF'); expect(uppercase('ghi')).toEqual('GHI'); @@ -30,7 +30,7 @@ describe('uppercase', () => { }); describe('lowercase', () => { - xit('returns the lowercased string', () => { + it('returns the lowercased string', () => { expect(lowercase('ABC')).toEqual('abc'); expect(lowercase('DEF')).toEqual('def'); expect(lowercase('GHI')).toEqual('ghi'); @@ -38,7 +38,7 @@ describe('lowercase', () => { }); describe('countCharacters', () => { - xit('returns the number of characters in the string', () => { + it('returns the number of characters in the string', () => { expect(countCharacters('fsfsgsfdg')).toEqual(9); expect(countCharacters('fsfsg')).toEqual(5); expect(countCharacters('')).toEqual(0); @@ -46,7 +46,7 @@ describe('countCharacters', () => { }); describe('firstCharacter', () => { - xit('returns the first character of the string', () => { + it('returns the first character of the string', () => { expect(firstCharacter('ABC')).toEqual('A'); expect(firstCharacter('DEF')).toEqual('D'); expect(firstCharacter('GHI')).toEqual('G'); @@ -54,11 +54,11 @@ describe('firstCharacter', () => { }); describe('firstCharacters', () => { - xit('returns the first 4 characters of the string', () => { + it('returns the first 4 characters of the string', () => { expect(firstCharacters('sd32fg45', 4)).toEqual('sd32'); }); - xit('returns the first 2 characters of the string', () => { + it('returns the first 2 characters of the string', () => { expect(firstCharacters('asd', 2)).toEqual('as'); }); }); diff --git a/src/strings.js b/src/strings.js index ce02aff..170f284 100644 --- a/src/strings.js +++ b/src/strings.js @@ -1,25 +1,25 @@ function sayHello (string) { - // your code here + return `Hello, ${string}!` }; function uppercase (string) { - // your code here + return string.toUpperCase() }; function lowercase (string) { - // your code here + return string.toLowerCase() }; function countCharacters (string) { - // your code here + return string.length }; function firstCharacter (string) { - // your code here + return string.charAt(0) }; function firstCharacters (string, n) { - // your code here + return string.substr(0, n) }; module.exports = { From d68a8ffa76b1be6d0876763ad2abb06224715ba2 Mon Sep 17 00:00:00 2001 From: AJ Lobb Date: Mon, 28 Feb 2022 14:29:08 +0000 Subject: [PATCH 09/22] passed the find by name test --- src/objects.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/objects.js b/src/objects.js index 7c14a99..fb6839b 100644 --- a/src/objects.js +++ b/src/objects.js @@ -47,7 +47,13 @@ const getAges = people => { }; const findByName = (name, people) => { - // your code here + for (i = 0; i < people.length; i++){ + const person = people[i] + if (person.name == name){ + return person + } + + } }; const findHondas = cars => { From bdaddc9e72daf09a0f9b932005130ab4bcac0305 Mon Sep 17 00:00:00 2001 From: AJ Lobb Date: Mon, 28 Feb 2022 15:08:05 +0000 Subject: [PATCH 10/22] test average age and HONDA passes --- src/objects.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/objects.js b/src/objects.js index fb6839b..1d7eaf9 100644 --- a/src/objects.js +++ b/src/objects.js @@ -57,15 +57,30 @@ const findByName = (name, people) => { }; const findHondas = cars => { - // your code here + let output= [] + for (i = 0; i < cars.length; i++){ + const car = cars[i] + if (car.manufacturer == "Honda"){ + output.push(car) + } + + }; + return output }; const averageAge = people => { - // your code here + let NoPeople = 0 + let TotalAge = 0 + for (i = 0; i < people.length; i++){ + const person = people[i] + TotalAge = TotalAge + person.age + NoPeople = NoPeople + 1 + } + return (TotalAge/NoPeople) }; const createTalkingPerson = (name, age) => { - // your code here + }; module.exports = { From 2581e34f604fd64a34ae65714c49c274b0291751 Mon Sep 17 00:00:00 2001 From: Wes <76014409+Redtigercod4@users.noreply.github.com> Date: Mon, 28 Feb 2022 15:20:56 +0000 Subject: [PATCH 11/22] Booleans & numbers completed --- src/__tests__/booleans.test.js | 30 +++++++++++------------ src/__tests__/numbers.test.js | 18 +++++++------- src/booleans.js | 44 +++++++++++++++++++++------------- src/numbers.js | 26 +++++++++++++------- 4 files changed, 69 insertions(+), 49 deletions(-) diff --git a/src/__tests__/booleans.test.js b/src/__tests__/booleans.test.js index 734201d..d647755 100644 --- a/src/__tests__/booleans.test.js +++ b/src/__tests__/booleans.test.js @@ -17,14 +17,14 @@ const { } = require('../booleans'); describe('negate', () => { - xit('returns the opposite of the passed boolean value', () => { + it('returns the opposite of the passed boolean value', () => { expect(negate(true)).toBe(false); expect(negate(false)).toBe(true); }); }); describe('both', () => { - xit('returns true if both of the given booleans are true', () => { + it('returns true if both of the given booleans are true', () => { expect(both(true, true)).toBe(true); expect(both(true, false)).toBe(false); expect(both(false, true)).toBe(false); @@ -33,7 +33,7 @@ describe('both', () => { }); describe('either', () => { - xit('returns true if at least one of the given booleans are true', () => { + it('returns true if at least one of the given booleans are true', () => { expect(either(true, true)).toBe(true); expect(either(true, false)).toBe(true); expect(either(false, true)).toBe(true); @@ -42,7 +42,7 @@ describe('either', () => { }); describe('none', () => { - xit('returns true if neither of the given booleans are true', () => { + it('returns true if neither of the given booleans are true', () => { expect(none(true, true)).toBe(false); expect(none(true, false)).toBe(false); expect(none(false, true)).toBe(false); @@ -51,7 +51,7 @@ describe('none', () => { }); describe('one', () => { - xit('returns true if exactly one of the given booleans are true', () => { + it('returns true if exactly one of the given booleans are true', () => { expect(one(true, true)).toBe(false); expect(one(true, false)).toBe(true); expect(one(false, true)).toBe(true); @@ -60,7 +60,7 @@ describe('one', () => { }); describe('truthiness', () => { - xit('returns the truthiness of the given value', () => { + it('returns the truthiness of the given value', () => { expect(truthiness('')).toBe(false); expect(truthiness('dbbd')).toBe(true); expect(truthiness(0)).toBe(false); @@ -74,7 +74,7 @@ describe('truthiness', () => { }); describe('isEqual', () => { - xit('returns whether the two values are equal', () => { + it('returns whether the two values are equal', () => { expect(isEqual(true, false)).toBe(false); expect(isEqual(true, true)).toBe(true); expect(isEqual('true', 'true')).toBe(true); @@ -86,7 +86,7 @@ describe('isEqual', () => { }); describe('isGreaterThan', () => { - xit('returns true if the first number is strictly greater than the second', () => { + it('returns true if the first number is strictly greater than the second', () => { expect(isGreaterThan(1, 2)).toBe(false); expect(isGreaterThan(3, 2)).toBe(true); expect(isGreaterThan(4, 4)).toBe(false); @@ -98,7 +98,7 @@ describe('isGreaterThan', () => { }); describe('isLessThanOrEqualTo', () => { - xit('returns true if the first number is less than or equal to the second', () => { + it('returns true if the first number is less than or equal to the second', () => { expect(isLessThanOrEqualTo(1, 2)).toBe(true); expect(isLessThanOrEqualTo(3, 2)).toBe(false); expect(isLessThanOrEqualTo(4, 4)).toBe(true); @@ -108,7 +108,7 @@ describe('isLessThanOrEqualTo', () => { }); describe('isOdd', () => { - xit('returns whether the number is odd', () => { + it('returns whether the number is odd', () => { expect(isOdd(5)).toBe(true); expect(isOdd(6)).toBe(false); expect(isOdd(7)).toBe(true); @@ -117,7 +117,7 @@ describe('isOdd', () => { }); describe('isEven', () => { - xit('returns whether the number is even', () => { + it('returns whether the number is even', () => { expect(isEven(5)).toBe(false); expect(isEven(6)).toBe(true); expect(isEven(7)).toBe(false); @@ -126,7 +126,7 @@ describe('isEven', () => { }); describe('isSquare', () => { - xit('returns true if the number is a square', () => { + it('returns true if the number is a square', () => { expect(isSquare(9)).toEqual(true); expect(isSquare(4)).toEqual(true); expect(isSquare(5)).toEqual(false); @@ -136,7 +136,7 @@ describe('isSquare', () => { }); describe('startsWith', () => { - xit('returns whether the given string starts with the given character', () => { + it('returns whether the given string starts with the given character', () => { expect(startsWith('a', 'aardvark')).toBe(true); expect(startsWith('c', 'aardvark')).toBe(false); expect(startsWith('b', 'baardvark')).toBe(true); @@ -146,7 +146,7 @@ describe('startsWith', () => { }); describe('containsVowels', () => { - xit('returns whether the given string contains vowels', () => { + it('returns whether the given string contains vowels', () => { expect(containsVowels('cat')).toBe(true); expect(containsVowels('DOG')).toBe(true); expect(containsVowels('why')).toBe(false); @@ -154,7 +154,7 @@ describe('containsVowels', () => { }); describe('isLowerCase', () => { - xit('it returns true if the given string is lowercase', () => { + it('it returns true if the given string is lowercase', () => { expect(isLowerCase('abc')).toBe(true); expect(isLowerCase('abc213')).toBe(true); expect(isLowerCase('Abc')).toBe(false); diff --git a/src/__tests__/numbers.test.js b/src/__tests__/numbers.test.js index 1cb4961..468413f 100644 --- a/src/__tests__/numbers.test.js +++ b/src/__tests__/numbers.test.js @@ -11,7 +11,7 @@ const { } = require('../numbers'); describe('add', () => { - xit('adds the two numbers together', () => { + it('adds the two numbers together', () => { expect(add(2, 1)).toEqual(3); expect(add(15, 76)).toEqual(91); expect(add(12, 0)).toEqual(12); @@ -20,7 +20,7 @@ describe('add', () => { }); describe('subtract', () => { - xit('subtracts the second number from the first', () => { + it('subtracts the second number from the first', () => { expect(subtract(2, 1)).toEqual(1); expect(subtract(1, 2)).toEqual(-1); expect(subtract(-2, 1)).toEqual(-3); @@ -30,7 +30,7 @@ describe('subtract', () => { }); describe('multiply', () => { - xit('multiplies the two numbers together', () => { + it('multiplies the two numbers together', () => { expect(multiply(10, 3)).toEqual(30); expect(multiply(-11, 5)).toEqual(-55); expect(multiply(-4, -9)).toEqual(36); @@ -38,7 +38,7 @@ describe('multiply', () => { }); describe('divide', () => { - xit('divides the first number by the second number', () => { + it('divides the first number by the second number', () => { expect(divide(20, 5)).toEqual(4); expect(divide(5, 2)).toEqual(2.5); expect(divide(2, 5)).toEqual(0.4); @@ -47,7 +47,7 @@ describe('divide', () => { }); describe('power', () => { - xit('returns the first number to the power of the second', () => { + it('returns the first number to the power of the second', () => { expect(power(5, 2)).toEqual(25); expect(power(2, 3)).toEqual(8); expect(power(10, 5)).toEqual(100000); @@ -55,7 +55,7 @@ describe('power', () => { }); describe('round', () => { - xit('rounds the number to the nearest integer', () => { + it('rounds the number to the nearest integer', () => { expect(round(2.1)).toEqual(2); expect(round(9.7)).toEqual(10); expect(round(5.5)).toEqual(6); @@ -63,7 +63,7 @@ describe('round', () => { }); describe('roundUp', () => { - xit('rounds the number up to the nearest integer', () => { + it('rounds the number up to the nearest integer', () => { expect(roundUp(2.1)).toEqual(3); expect(roundUp(9.7)).toEqual(10); expect(roundUp(5.5)).toEqual(6); @@ -71,7 +71,7 @@ describe('roundUp', () => { }); describe('roundDown', () => { - xit('rounds the number down to the nearest integer', () => { + it('rounds the number down to the nearest integer', () => { expect(roundDown(2.1)).toEqual(2); expect(roundDown(9.7)).toEqual(9); expect(roundDown(5.5)).toEqual(5); @@ -79,7 +79,7 @@ describe('roundDown', () => { }); describe('absolute', () => { - xit('returns the absolute value of the number', () => { + it('returns the absolute value of the number', () => { expect(absolute(-1)).toEqual(1); expect(absolute(1)).toEqual(1); expect(absolute(0)).toEqual(0); diff --git a/src/booleans.js b/src/booleans.js index 5ff6cb5..3706add 100644 --- a/src/booleans.js +++ b/src/booleans.js @@ -1,61 +1,73 @@ function negate(a) { - // your code here + return !a }; function both(a, b) { - // your code here + return a && b }; function either(a, b) { - // your code here + return a || b }; function none(a, b) { - // your code here + if (a || b == true){ + return false + } else { + return true + } }; function one(a, b) { - // your code here + if (a && b) { + return false; + } + return a || b; }; function truthiness(a) { - // your code here + if (a) { + return true; + } else { + return false; + } }; function isEqual(a, b) { - // your code here + return a === b }; function isGreaterThan(a, b) { - // your code here + return a > b }; function isLessThanOrEqualTo(a, b) { - // your code here -}; + return a <= b +} function isOdd(a) { - // your code here + return a % 2 == 1 }; function isEven(a) { - // your code here + return a % 2 == 0 }; function isSquare(a) { - // your code here + return Math.sqrt(a) % 1 === 0 }; function startsWith(char, string) { - // your code here + return string.startsWith(char) }; function containsVowels(string) { - // your code here + let reg = /[aeiou]/gi + return reg.test(string) }; function isLowerCase(string) { - // your code here + return string == string.toLowerCase() }; module.exports = { diff --git a/src/numbers.js b/src/numbers.js index 9d192c9..06df357 100644 --- a/src/numbers.js +++ b/src/numbers.js @@ -1,39 +1,47 @@ function add (a, b) { - // your code here + return a + b } function subtract (a, b) { - // your code here + return a - b } function multiply (a, b) { - // your code here + return a * b } function divide (a, b) { - // your code here + return a / b } function power (a, b) { - // your code here + return Math.pow(a, b) } function round (a) { - // your code here + return Math.round(a); } + + function roundUp (a) { - // your code here + return Math.ceil(a); } + + function roundDown (a) { - // your code here + return Math.floor(a); } + + function absolute (a) { - // your code here + return Math.abs(a); } + + module.exports = { add, subtract, From ff07b7103bb32baad005b9a7a43e51b9048c9f87 Mon Sep 17 00:00:00 2001 From: HWSolo Date: Mon, 28 Feb 2022 15:34:37 +0000 Subject: [PATCH 12/22] ArraysUpdate Update --- src/__tests__/arrays.test.js | 16 ++++++++-------- src/arrays.js | 35 +++++++++++++++++++++++------------ 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/__tests__/arrays.test.js b/src/__tests__/arrays.test.js index d00a556..34323a9 100644 --- a/src/__tests__/arrays.test.js +++ b/src/__tests__/arrays.test.js @@ -19,34 +19,34 @@ const { describe('getNthElement', () => { const array = ['cat', 'dog', 'elephant', 'fox']; - xit('returns the element at the given position', () => { + it('returns the element at the given position', () => { expect(getNthElement(0, array)).toEqual('cat'); expect(getNthElement(2, array)).toEqual('elephant'); expect(getNthElement(3, array)).toEqual('fox'); }); - xit('if n is greater than the number of elements, it cycles back to the start', () => { + it('if n is greater than the number of elements, it cycles back to the start', () => { expect(getNthElement(4, array)).toEqual('cat'); expect(getNthElement(5, array)).toEqual('dog'); }); }); describe('arrayToCSVString', () => { - xit('returns the array elements as a comma-seperated string', () => { + it('returns the array elements as a comma-seperated string', () => { expect(arrayToCSVString(['a', 'b', 'c', 'd'])).toEqual('a,b,c,d'); expect(arrayToCSVString([1, 2, 3, 4, 5])).toEqual('1,2,3,4,5'); }); }); describe('csvStringToArray', () => { - xit('converts the csv string as an array', () => { + it('converts the csv string as an array', () => { expect(csvStringToArray('a,b,c,d')).toEqual(['a', 'b', 'c', 'd']); expect(csvStringToArray('1,2,3,4,5')).toEqual(['1', '2', '3', '4', '5']); }); }); describe('addToArray', () => { - xit('adds the item to the end of the array', () => { + it('adds the item to the end of the array', () => { const array = []; const array2 = [1, 2, 3]; @@ -59,7 +59,7 @@ describe('addToArray', () => { }); describe('addToArray2', () => { - xit('returns a new array with the value appended', () => { + it('returns a new array with the value appended', () => { const array = ['a', 'b', 'c']; const array2 = [1, 2, 3]; @@ -72,7 +72,7 @@ describe('addToArray2', () => { }); describe('removeNthElement', () => { - xit('removes the element at position n', () => { + it('removes the element at position n', () => { const array = ['ant', 'bison', 'cockerel', 'duck', 'elephant']; removeNthElement(2, array); expect(array).toEqual(['ant', 'bison', 'duck', 'elephant']); @@ -84,7 +84,7 @@ describe('removeNthElement', () => { }); describe('numbersToStrings', () => { - xit('converts every number in the array to a string', () => { + it('converts every number in the array to a string', () => { expect(numbersToStrings([1, 2, 3])).toEqual(['1', '2', '3']); expect(numbersToStrings([7, 8, 9])).toEqual(['7', '8', '9']); }); diff --git a/src/arrays.js b/src/arrays.js index 822c49b..ef6422b 100644 --- a/src/arrays.js +++ b/src/arrays.js @@ -1,37 +1,48 @@ const getNthElement = (index, array) => { - // your code here + while (index >= array.length) { + index=index-array.length; + } + return array[index] }; const arrayToCSVString = array => { - // your code here + return array.join(",") }; const csvStringToArray = string => { - // your code here + return string.split(",") }; -const addToArray = (element, array) => { - // your code here +const addToArray = (element, array) => { + array.push(element) }; -const addToArray2 = (element, array) => { - // your code here +const addToArray2 = (element, array) => { + let array2 = [...array]; + array2.push(element) + return array2; }; -const removeNthElement = (index, array) => { - // your code here +const removeNthElement = (index, array) => { + array.splice(index, 1) + return array; }; const numbersToStrings = numbers => { - // your code here + let output = [] + for (i = 0; i < numbers.length; i++){ + const number = numbers[i] + output.push(number.toString()) + } + return output; }; const uppercaseWordsInArray = strings => { - // your code here + return }; const reverseWordsInArray = strings => { - // your code here + return }; const onlyEven = numbers => { From f9ce2c108baa725b84428a2c951d030d8594c222 Mon Sep 17 00:00:00 2001 From: AJ Lobb Date: Mon, 28 Feb 2022 15:41:05 +0000 Subject: [PATCH 13/22] Finished createTalkingPerson --- src/objects.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/objects.js b/src/objects.js index 1d7eaf9..93286ca 100644 --- a/src/objects.js +++ b/src/objects.js @@ -80,9 +80,23 @@ const averageAge = people => { }; const createTalkingPerson = (name, age) => { - + let person = { + introduce: (hi) => { + return "Hi " + hi + ", my name is " + name + " and I am " + age + "!" + }, + name: name, + age: age + } + return person }; + +//{ + //a: variable, + //b: function() {}, + //c: variable + //} + module.exports = { createPerson, getName, From 62d7face0cf0ffabae0115ab532b48c12b6a74ac Mon Sep 17 00:00:00 2001 From: Wes <76014409+Redtigercod4@users.noreply.github.com> Date: Mon, 28 Feb 2022 15:42:00 +0000 Subject: [PATCH 14/22] arrays work --- src/__tests__/arrays.test.js | 8 ++++---- src/arrays.js | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/__tests__/arrays.test.js b/src/__tests__/arrays.test.js index d00a556..f6f3587 100644 --- a/src/__tests__/arrays.test.js +++ b/src/__tests__/arrays.test.js @@ -19,27 +19,27 @@ const { describe('getNthElement', () => { const array = ['cat', 'dog', 'elephant', 'fox']; - xit('returns the element at the given position', () => { + it('returns the element at the given position', () => { expect(getNthElement(0, array)).toEqual('cat'); expect(getNthElement(2, array)).toEqual('elephant'); expect(getNthElement(3, array)).toEqual('fox'); }); - xit('if n is greater than the number of elements, it cycles back to the start', () => { + it('if n is greater than the number of elements, it cycles back to the start', () => { expect(getNthElement(4, array)).toEqual('cat'); expect(getNthElement(5, array)).toEqual('dog'); }); }); describe('arrayToCSVString', () => { - xit('returns the array elements as a comma-seperated string', () => { + it('returns the array elements as a comma-seperated string', () => { expect(arrayToCSVString(['a', 'b', 'c', 'd'])).toEqual('a,b,c,d'); expect(arrayToCSVString([1, 2, 3, 4, 5])).toEqual('1,2,3,4,5'); }); }); describe('csvStringToArray', () => { - xit('converts the csv string as an array', () => { + it('converts the csv string as an array', () => { expect(csvStringToArray('a,b,c,d')).toEqual(['a', 'b', 'c', 'd']); expect(csvStringToArray('1,2,3,4,5')).toEqual(['1', '2', '3', '4', '5']); }); diff --git a/src/arrays.js b/src/arrays.js index 822c49b..9a98ffa 100644 --- a/src/arrays.js +++ b/src/arrays.js @@ -1,13 +1,13 @@ const getNthElement = (index, array) => { - // your code here + return array[index] }; const arrayToCSVString = array => { - // your code here + return array.toString() }; const csvStringToArray = string => { - // your code here + return array.split() }; const addToArray = (element, array) => { @@ -19,7 +19,7 @@ const addToArray2 = (element, array) => { }; const removeNthElement = (index, array) => { - // your code here + return array.splice(index, 1) }; const numbersToStrings = numbers => { From f6c62f8ae2d1e386dde3e90729cbaa394f606429 Mon Sep 17 00:00:00 2001 From: Wes <76014409+Redtigercod4@users.noreply.github.com> Date: Mon, 28 Feb 2022 15:44:29 +0000 Subject: [PATCH 15/22] Revert "Strings JS complete" This reverts commit 0e28981a03db868c906d98c7311a79d4b4b43a6a. --- src/__tests__/strings.test.js | 18 +++++++++--------- src/strings.js | 12 ++++++------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/__tests__/strings.test.js b/src/__tests__/strings.test.js index b19fd73..e2c3c88 100644 --- a/src/__tests__/strings.test.js +++ b/src/__tests__/strings.test.js @@ -8,21 +8,21 @@ const { } = require('../strings'); describe('sayHello', () => { - it('returns "Hello world!" when passed "world"', () => { + xit('returns "Hello world!" when passed "world"', () => { expect(sayHello('world')).toEqual('Hello, world!'); }); - it('returns "Hello MCR Codes!" when passed "MCR Codes"', () => { + xit('returns "Hello MCR Codes!" when passed "MCR Codes"', () => { expect(sayHello('MCR Codes')).toEqual('Hello, MCR Codes!'); }); - it('returns "Hello fsghjdfkhgf!" when passed "fsghjdfkhgf"', () => { + xit('returns "Hello fsghjdfkhgf!" when passed "fsghjdfkhgf"', () => { expect(sayHello('fsghjdfkhgf')).toEqual('Hello, fsghjdfkhgf!'); }); }); describe('uppercase', () => { - it('returns the uppercased string', () => { + xit('returns the uppercased string', () => { expect(uppercase('abc')).toEqual('ABC'); expect(uppercase('def')).toEqual('DEF'); expect(uppercase('ghi')).toEqual('GHI'); @@ -30,7 +30,7 @@ describe('uppercase', () => { }); describe('lowercase', () => { - it('returns the lowercased string', () => { + xit('returns the lowercased string', () => { expect(lowercase('ABC')).toEqual('abc'); expect(lowercase('DEF')).toEqual('def'); expect(lowercase('GHI')).toEqual('ghi'); @@ -38,7 +38,7 @@ describe('lowercase', () => { }); describe('countCharacters', () => { - it('returns the number of characters in the string', () => { + xit('returns the number of characters in the string', () => { expect(countCharacters('fsfsgsfdg')).toEqual(9); expect(countCharacters('fsfsg')).toEqual(5); expect(countCharacters('')).toEqual(0); @@ -46,7 +46,7 @@ describe('countCharacters', () => { }); describe('firstCharacter', () => { - it('returns the first character of the string', () => { + xit('returns the first character of the string', () => { expect(firstCharacter('ABC')).toEqual('A'); expect(firstCharacter('DEF')).toEqual('D'); expect(firstCharacter('GHI')).toEqual('G'); @@ -54,11 +54,11 @@ describe('firstCharacter', () => { }); describe('firstCharacters', () => { - it('returns the first 4 characters of the string', () => { + xit('returns the first 4 characters of the string', () => { expect(firstCharacters('sd32fg45', 4)).toEqual('sd32'); }); - it('returns the first 2 characters of the string', () => { + xit('returns the first 2 characters of the string', () => { expect(firstCharacters('asd', 2)).toEqual('as'); }); }); diff --git a/src/strings.js b/src/strings.js index 170f284..ce02aff 100644 --- a/src/strings.js +++ b/src/strings.js @@ -1,25 +1,25 @@ function sayHello (string) { - return `Hello, ${string}!` + // your code here }; function uppercase (string) { - return string.toUpperCase() + // your code here }; function lowercase (string) { - return string.toLowerCase() + // your code here }; function countCharacters (string) { - return string.length + // your code here }; function firstCharacter (string) { - return string.charAt(0) + // your code here }; function firstCharacters (string, n) { - return string.substr(0, n) + // your code here }; module.exports = { From 44df0a4708da9f7dca5ecee7410b67ac20c551a0 Mon Sep 17 00:00:00 2001 From: Wes <76014409+Redtigercod4@users.noreply.github.com> Date: Mon, 28 Feb 2022 15:44:32 +0000 Subject: [PATCH 16/22] Revert "Booleans & numbers completed" This reverts commit 2581e34f604fd64a34ae65714c49c274b0291751. --- src/__tests__/booleans.test.js | 30 +++++++++++------------ src/__tests__/numbers.test.js | 18 +++++++------- src/booleans.js | 44 +++++++++++++--------------------- src/numbers.js | 26 +++++++------------- 4 files changed, 49 insertions(+), 69 deletions(-) diff --git a/src/__tests__/booleans.test.js b/src/__tests__/booleans.test.js index d647755..734201d 100644 --- a/src/__tests__/booleans.test.js +++ b/src/__tests__/booleans.test.js @@ -17,14 +17,14 @@ const { } = require('../booleans'); describe('negate', () => { - it('returns the opposite of the passed boolean value', () => { + xit('returns the opposite of the passed boolean value', () => { expect(negate(true)).toBe(false); expect(negate(false)).toBe(true); }); }); describe('both', () => { - it('returns true if both of the given booleans are true', () => { + xit('returns true if both of the given booleans are true', () => { expect(both(true, true)).toBe(true); expect(both(true, false)).toBe(false); expect(both(false, true)).toBe(false); @@ -33,7 +33,7 @@ describe('both', () => { }); describe('either', () => { - it('returns true if at least one of the given booleans are true', () => { + xit('returns true if at least one of the given booleans are true', () => { expect(either(true, true)).toBe(true); expect(either(true, false)).toBe(true); expect(either(false, true)).toBe(true); @@ -42,7 +42,7 @@ describe('either', () => { }); describe('none', () => { - it('returns true if neither of the given booleans are true', () => { + xit('returns true if neither of the given booleans are true', () => { expect(none(true, true)).toBe(false); expect(none(true, false)).toBe(false); expect(none(false, true)).toBe(false); @@ -51,7 +51,7 @@ describe('none', () => { }); describe('one', () => { - it('returns true if exactly one of the given booleans are true', () => { + xit('returns true if exactly one of the given booleans are true', () => { expect(one(true, true)).toBe(false); expect(one(true, false)).toBe(true); expect(one(false, true)).toBe(true); @@ -60,7 +60,7 @@ describe('one', () => { }); describe('truthiness', () => { - it('returns the truthiness of the given value', () => { + xit('returns the truthiness of the given value', () => { expect(truthiness('')).toBe(false); expect(truthiness('dbbd')).toBe(true); expect(truthiness(0)).toBe(false); @@ -74,7 +74,7 @@ describe('truthiness', () => { }); describe('isEqual', () => { - it('returns whether the two values are equal', () => { + xit('returns whether the two values are equal', () => { expect(isEqual(true, false)).toBe(false); expect(isEqual(true, true)).toBe(true); expect(isEqual('true', 'true')).toBe(true); @@ -86,7 +86,7 @@ describe('isEqual', () => { }); describe('isGreaterThan', () => { - it('returns true if the first number is strictly greater than the second', () => { + xit('returns true if the first number is strictly greater than the second', () => { expect(isGreaterThan(1, 2)).toBe(false); expect(isGreaterThan(3, 2)).toBe(true); expect(isGreaterThan(4, 4)).toBe(false); @@ -98,7 +98,7 @@ describe('isGreaterThan', () => { }); describe('isLessThanOrEqualTo', () => { - it('returns true if the first number is less than or equal to the second', () => { + xit('returns true if the first number is less than or equal to the second', () => { expect(isLessThanOrEqualTo(1, 2)).toBe(true); expect(isLessThanOrEqualTo(3, 2)).toBe(false); expect(isLessThanOrEqualTo(4, 4)).toBe(true); @@ -108,7 +108,7 @@ describe('isLessThanOrEqualTo', () => { }); describe('isOdd', () => { - it('returns whether the number is odd', () => { + xit('returns whether the number is odd', () => { expect(isOdd(5)).toBe(true); expect(isOdd(6)).toBe(false); expect(isOdd(7)).toBe(true); @@ -117,7 +117,7 @@ describe('isOdd', () => { }); describe('isEven', () => { - it('returns whether the number is even', () => { + xit('returns whether the number is even', () => { expect(isEven(5)).toBe(false); expect(isEven(6)).toBe(true); expect(isEven(7)).toBe(false); @@ -126,7 +126,7 @@ describe('isEven', () => { }); describe('isSquare', () => { - it('returns true if the number is a square', () => { + xit('returns true if the number is a square', () => { expect(isSquare(9)).toEqual(true); expect(isSquare(4)).toEqual(true); expect(isSquare(5)).toEqual(false); @@ -136,7 +136,7 @@ describe('isSquare', () => { }); describe('startsWith', () => { - it('returns whether the given string starts with the given character', () => { + xit('returns whether the given string starts with the given character', () => { expect(startsWith('a', 'aardvark')).toBe(true); expect(startsWith('c', 'aardvark')).toBe(false); expect(startsWith('b', 'baardvark')).toBe(true); @@ -146,7 +146,7 @@ describe('startsWith', () => { }); describe('containsVowels', () => { - it('returns whether the given string contains vowels', () => { + xit('returns whether the given string contains vowels', () => { expect(containsVowels('cat')).toBe(true); expect(containsVowels('DOG')).toBe(true); expect(containsVowels('why')).toBe(false); @@ -154,7 +154,7 @@ describe('containsVowels', () => { }); describe('isLowerCase', () => { - it('it returns true if the given string is lowercase', () => { + xit('it returns true if the given string is lowercase', () => { expect(isLowerCase('abc')).toBe(true); expect(isLowerCase('abc213')).toBe(true); expect(isLowerCase('Abc')).toBe(false); diff --git a/src/__tests__/numbers.test.js b/src/__tests__/numbers.test.js index 468413f..1cb4961 100644 --- a/src/__tests__/numbers.test.js +++ b/src/__tests__/numbers.test.js @@ -11,7 +11,7 @@ const { } = require('../numbers'); describe('add', () => { - it('adds the two numbers together', () => { + xit('adds the two numbers together', () => { expect(add(2, 1)).toEqual(3); expect(add(15, 76)).toEqual(91); expect(add(12, 0)).toEqual(12); @@ -20,7 +20,7 @@ describe('add', () => { }); describe('subtract', () => { - it('subtracts the second number from the first', () => { + xit('subtracts the second number from the first', () => { expect(subtract(2, 1)).toEqual(1); expect(subtract(1, 2)).toEqual(-1); expect(subtract(-2, 1)).toEqual(-3); @@ -30,7 +30,7 @@ describe('subtract', () => { }); describe('multiply', () => { - it('multiplies the two numbers together', () => { + xit('multiplies the two numbers together', () => { expect(multiply(10, 3)).toEqual(30); expect(multiply(-11, 5)).toEqual(-55); expect(multiply(-4, -9)).toEqual(36); @@ -38,7 +38,7 @@ describe('multiply', () => { }); describe('divide', () => { - it('divides the first number by the second number', () => { + xit('divides the first number by the second number', () => { expect(divide(20, 5)).toEqual(4); expect(divide(5, 2)).toEqual(2.5); expect(divide(2, 5)).toEqual(0.4); @@ -47,7 +47,7 @@ describe('divide', () => { }); describe('power', () => { - it('returns the first number to the power of the second', () => { + xit('returns the first number to the power of the second', () => { expect(power(5, 2)).toEqual(25); expect(power(2, 3)).toEqual(8); expect(power(10, 5)).toEqual(100000); @@ -55,7 +55,7 @@ describe('power', () => { }); describe('round', () => { - it('rounds the number to the nearest integer', () => { + xit('rounds the number to the nearest integer', () => { expect(round(2.1)).toEqual(2); expect(round(9.7)).toEqual(10); expect(round(5.5)).toEqual(6); @@ -63,7 +63,7 @@ describe('round', () => { }); describe('roundUp', () => { - it('rounds the number up to the nearest integer', () => { + xit('rounds the number up to the nearest integer', () => { expect(roundUp(2.1)).toEqual(3); expect(roundUp(9.7)).toEqual(10); expect(roundUp(5.5)).toEqual(6); @@ -71,7 +71,7 @@ describe('roundUp', () => { }); describe('roundDown', () => { - it('rounds the number down to the nearest integer', () => { + xit('rounds the number down to the nearest integer', () => { expect(roundDown(2.1)).toEqual(2); expect(roundDown(9.7)).toEqual(9); expect(roundDown(5.5)).toEqual(5); @@ -79,7 +79,7 @@ describe('roundDown', () => { }); describe('absolute', () => { - it('returns the absolute value of the number', () => { + xit('returns the absolute value of the number', () => { expect(absolute(-1)).toEqual(1); expect(absolute(1)).toEqual(1); expect(absolute(0)).toEqual(0); diff --git a/src/booleans.js b/src/booleans.js index 3706add..5ff6cb5 100644 --- a/src/booleans.js +++ b/src/booleans.js @@ -1,73 +1,61 @@ function negate(a) { - return !a + // your code here }; function both(a, b) { - return a && b + // your code here }; function either(a, b) { - return a || b + // your code here }; function none(a, b) { - if (a || b == true){ - return false - } else { - return true - } + // your code here }; function one(a, b) { - if (a && b) { - return false; - } - return a || b; + // your code here }; function truthiness(a) { - if (a) { - return true; - } else { - return false; - } + // your code here }; function isEqual(a, b) { - return a === b + // your code here }; function isGreaterThan(a, b) { - return a > b + // your code here }; function isLessThanOrEqualTo(a, b) { - return a <= b -} + // your code here +}; function isOdd(a) { - return a % 2 == 1 + // your code here }; function isEven(a) { - return a % 2 == 0 + // your code here }; function isSquare(a) { - return Math.sqrt(a) % 1 === 0 + // your code here }; function startsWith(char, string) { - return string.startsWith(char) + // your code here }; function containsVowels(string) { - let reg = /[aeiou]/gi - return reg.test(string) + // your code here }; function isLowerCase(string) { - return string == string.toLowerCase() + // your code here }; module.exports = { diff --git a/src/numbers.js b/src/numbers.js index 06df357..9d192c9 100644 --- a/src/numbers.js +++ b/src/numbers.js @@ -1,47 +1,39 @@ function add (a, b) { - return a + b + // your code here } function subtract (a, b) { - return a - b + // your code here } function multiply (a, b) { - return a * b + // your code here } function divide (a, b) { - return a / b + // your code here } function power (a, b) { - return Math.pow(a, b) + // your code here } function round (a) { - return Math.round(a); + // your code here } - - function roundUp (a) { - return Math.ceil(a); + // your code here } - - function roundDown (a) { - return Math.floor(a); + // your code here } - - function absolute (a) { - return Math.abs(a); + // your code here } - - module.exports = { add, subtract, From dc47df7b3c74c7deaccaeef8db6039a018d4d83b Mon Sep 17 00:00:00 2001 From: Wes <76014409+Redtigercod4@users.noreply.github.com> Date: Mon, 28 Feb 2022 15:44:34 +0000 Subject: [PATCH 17/22] Revert "arrays work" This reverts commit 62d7face0cf0ffabae0115ab532b48c12b6a74ac. --- src/__tests__/arrays.test.js | 8 ++++---- src/arrays.js | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/__tests__/arrays.test.js b/src/__tests__/arrays.test.js index f6f3587..d00a556 100644 --- a/src/__tests__/arrays.test.js +++ b/src/__tests__/arrays.test.js @@ -19,27 +19,27 @@ const { describe('getNthElement', () => { const array = ['cat', 'dog', 'elephant', 'fox']; - it('returns the element at the given position', () => { + xit('returns the element at the given position', () => { expect(getNthElement(0, array)).toEqual('cat'); expect(getNthElement(2, array)).toEqual('elephant'); expect(getNthElement(3, array)).toEqual('fox'); }); - it('if n is greater than the number of elements, it cycles back to the start', () => { + xit('if n is greater than the number of elements, it cycles back to the start', () => { expect(getNthElement(4, array)).toEqual('cat'); expect(getNthElement(5, array)).toEqual('dog'); }); }); describe('arrayToCSVString', () => { - it('returns the array elements as a comma-seperated string', () => { + xit('returns the array elements as a comma-seperated string', () => { expect(arrayToCSVString(['a', 'b', 'c', 'd'])).toEqual('a,b,c,d'); expect(arrayToCSVString([1, 2, 3, 4, 5])).toEqual('1,2,3,4,5'); }); }); describe('csvStringToArray', () => { - it('converts the csv string as an array', () => { + xit('converts the csv string as an array', () => { expect(csvStringToArray('a,b,c,d')).toEqual(['a', 'b', 'c', 'd']); expect(csvStringToArray('1,2,3,4,5')).toEqual(['1', '2', '3', '4', '5']); }); diff --git a/src/arrays.js b/src/arrays.js index 9a98ffa..822c49b 100644 --- a/src/arrays.js +++ b/src/arrays.js @@ -1,13 +1,13 @@ const getNthElement = (index, array) => { - return array[index] + // your code here }; const arrayToCSVString = array => { - return array.toString() + // your code here }; const csvStringToArray = string => { - return array.split() + // your code here }; const addToArray = (element, array) => { @@ -19,7 +19,7 @@ const addToArray2 = (element, array) => { }; const removeNthElement = (index, array) => { - return array.splice(index, 1) + // your code here }; const numbersToStrings = numbers => { From 08652ca883f02256bcf3d9704f17928e9deb6686 Mon Sep 17 00:00:00 2001 From: mini1998 <99973223+mini1998@users.noreply.github.com> Date: Mon, 28 Feb 2022 15:45:15 +0000 Subject: [PATCH 18/22] Update booleans.js --- src/booleans.js | 66 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 51 insertions(+), 15 deletions(-) diff --git a/src/booleans.js b/src/booleans.js index 5ff6cb5..0eda88c 100644 --- a/src/booleans.js +++ b/src/booleans.js @@ -1,61 +1,97 @@ function negate(a) { - // your code here + return !a }; function both(a, b) { - // your code here + return a && b }; function either(a, b) { - // your code here + return a || b }; function none(a, b) { - // your code here + return (a || b) == false }; function one(a, b) { - // your code here + if (a && b) { + return false + }; + return a || b }; function truthiness(a) { - // your code here + if (a) { + return true; + }else{ + return false; + } }; function isEqual(a, b) { - // your code here + return a === b }; function isGreaterThan(a, b) { - // your code here + return a > b }; function isLessThanOrEqualTo(a, b) { - // your code here + return a <= b }; function isOdd(a) { - // your code here + if (a % 2 === 0 ){ + return false; + } else { + return true; + } }; function isEven(a) { - // your code here + if (a%2 === 0){ + return true +} else { + return false +} }; function isSquare(a) { - // your code here + if(Math.sqrt(a) % 1 == 0){ + return true + }else { + return false + } }; function startsWith(char, string) { - // your code here + if(string.charAt(0) == char){ + return true + } else { + return false + } }; function containsVowels(string) { - // your code here + const checker = ["a", "e", "i", "o", "u" ] + string = string.toLowerCase() + for ( i = 0; i < checker.length; i ++) { + const letter = checker[i] + if (string.includes(letter)){ + return true + } + } + return false }; function isLowerCase(string) { - // your code here + if (string === string.toLowerCase()){ + return true + } else { + return false + } + }; module.exports = { From f24986b28dc772990ca12d2267d2272cadc409b5 Mon Sep 17 00:00:00 2001 From: mini1998 <99973223+mini1998@users.noreply.github.com> Date: Mon, 28 Feb 2022 15:45:33 +0000 Subject: [PATCH 19/22] Update booleans.test.js --- src/__tests__/booleans.test.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/__tests__/booleans.test.js b/src/__tests__/booleans.test.js index 734201d..890770a 100644 --- a/src/__tests__/booleans.test.js +++ b/src/__tests__/booleans.test.js @@ -17,14 +17,14 @@ const { } = require('../booleans'); describe('negate', () => { - xit('returns the opposite of the passed boolean value', () => { + it('returns the opposite of the passed boolean value', () => { expect(negate(true)).toBe(false); expect(negate(false)).toBe(true); }); }); describe('both', () => { - xit('returns true if both of the given booleans are true', () => { + it('returns true if both of the given booleans are true', () => { expect(both(true, true)).toBe(true); expect(both(true, false)).toBe(false); expect(both(false, true)).toBe(false); @@ -33,7 +33,7 @@ describe('both', () => { }); describe('either', () => { - xit('returns true if at least one of the given booleans are true', () => { +it('returns true if at least one of the given booleans are true', () => { expect(either(true, true)).toBe(true); expect(either(true, false)).toBe(true); expect(either(false, true)).toBe(true); @@ -42,7 +42,7 @@ describe('either', () => { }); describe('none', () => { - xit('returns true if neither of the given booleans are true', () => { + it('returns true if neither of the given booleans are true', () => { expect(none(true, true)).toBe(false); expect(none(true, false)).toBe(false); expect(none(false, true)).toBe(false); @@ -51,7 +51,7 @@ describe('none', () => { }); describe('one', () => { - xit('returns true if exactly one of the given booleans are true', () => { + it('returns true if exactly one of the given booleans are true', () => { expect(one(true, true)).toBe(false); expect(one(true, false)).toBe(true); expect(one(false, true)).toBe(true); @@ -60,7 +60,7 @@ describe('one', () => { }); describe('truthiness', () => { - xit('returns the truthiness of the given value', () => { + it('returns the truthiness of the given value', () => { expect(truthiness('')).toBe(false); expect(truthiness('dbbd')).toBe(true); expect(truthiness(0)).toBe(false); @@ -74,7 +74,7 @@ describe('truthiness', () => { }); describe('isEqual', () => { - xit('returns whether the two values are equal', () => { + it('returns whether the two values are equal', () => { expect(isEqual(true, false)).toBe(false); expect(isEqual(true, true)).toBe(true); expect(isEqual('true', 'true')).toBe(true); @@ -86,7 +86,7 @@ describe('isEqual', () => { }); describe('isGreaterThan', () => { - xit('returns true if the first number is strictly greater than the second', () => { + it('returns true if the first number is strictly greater than the second', () => { expect(isGreaterThan(1, 2)).toBe(false); expect(isGreaterThan(3, 2)).toBe(true); expect(isGreaterThan(4, 4)).toBe(false); @@ -98,7 +98,7 @@ describe('isGreaterThan', () => { }); describe('isLessThanOrEqualTo', () => { - xit('returns true if the first number is less than or equal to the second', () => { + it('returns true if the first number is less than or equal to the second', () => { expect(isLessThanOrEqualTo(1, 2)).toBe(true); expect(isLessThanOrEqualTo(3, 2)).toBe(false); expect(isLessThanOrEqualTo(4, 4)).toBe(true); @@ -108,7 +108,7 @@ describe('isLessThanOrEqualTo', () => { }); describe('isOdd', () => { - xit('returns whether the number is odd', () => { + it('returns whether the number is odd', () => { expect(isOdd(5)).toBe(true); expect(isOdd(6)).toBe(false); expect(isOdd(7)).toBe(true); @@ -117,7 +117,7 @@ describe('isOdd', () => { }); describe('isEven', () => { - xit('returns whether the number is even', () => { + it('returns whether the number is even', () => { expect(isEven(5)).toBe(false); expect(isEven(6)).toBe(true); expect(isEven(7)).toBe(false); @@ -126,7 +126,7 @@ describe('isEven', () => { }); describe('isSquare', () => { - xit('returns true if the number is a square', () => { + it('returns true if the number is a square', () => { expect(isSquare(9)).toEqual(true); expect(isSquare(4)).toEqual(true); expect(isSquare(5)).toEqual(false); @@ -136,7 +136,7 @@ describe('isSquare', () => { }); describe('startsWith', () => { - xit('returns whether the given string starts with the given character', () => { + it('returns whether the given string starts with the given character', () => { expect(startsWith('a', 'aardvark')).toBe(true); expect(startsWith('c', 'aardvark')).toBe(false); expect(startsWith('b', 'baardvark')).toBe(true); @@ -146,7 +146,7 @@ describe('startsWith', () => { }); describe('containsVowels', () => { - xit('returns whether the given string contains vowels', () => { + it('returns whether the given string contains vowels', () => { expect(containsVowels('cat')).toBe(true); expect(containsVowels('DOG')).toBe(true); expect(containsVowels('why')).toBe(false); @@ -154,7 +154,7 @@ describe('containsVowels', () => { }); describe('isLowerCase', () => { - xit('it returns true if the given string is lowercase', () => { + it('it returns true if the given string is lowercase', () => { expect(isLowerCase('abc')).toBe(true); expect(isLowerCase('abc213')).toBe(true); expect(isLowerCase('Abc')).toBe(false); From 7e56850ca9451bea8c88daa1b95d83d755d93bb7 Mon Sep 17 00:00:00 2001 From: MichealWilkinson-MT Date: Mon, 28 Feb 2022 16:36:46 +0000 Subject: [PATCH 20/22] Giving credit to MCRCodes --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d6da44d..5a33968 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # JavaScript Basics +This was lovingly coppied from [MCRcodes/javascript-basics](https://github.com/MCRcodes/javascript-basics) but modified for use in our 2022 bootcamp. All credit goes to [MCRCodes](https://github.com/MCRcodes) for the amazing work in this repo The repository contains test cases and empty function definitions which need to be populated to solve the different challenges set in this weeks walkthrough. 🚨*You should not update the tests!* 🚨 From d07c355eb21b32373702d6955f5587534bb6afff Mon Sep 17 00:00:00 2001 From: AJ Lobb Date: Tue, 1 Mar 2022 09:56:58 +0000 Subject: [PATCH 21/22] created code for removeSpaces and passes test --- src/__tests__/arrays.test.js | 18 +++++++++--------- src/arrays.js | 3 ++- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/__tests__/arrays.test.js b/src/__tests__/arrays.test.js index 34323a9..9626efe 100644 --- a/src/__tests__/arrays.test.js +++ b/src/__tests__/arrays.test.js @@ -19,34 +19,34 @@ const { describe('getNthElement', () => { const array = ['cat', 'dog', 'elephant', 'fox']; - it('returns the element at the given position', () => { + xit('returns the element at the given position', () => { expect(getNthElement(0, array)).toEqual('cat'); expect(getNthElement(2, array)).toEqual('elephant'); expect(getNthElement(3, array)).toEqual('fox'); }); - it('if n is greater than the number of elements, it cycles back to the start', () => { + xit('if n is greater than the number of elements, it cycles back to the start', () => { expect(getNthElement(4, array)).toEqual('cat'); expect(getNthElement(5, array)).toEqual('dog'); }); }); describe('arrayToCSVString', () => { - it('returns the array elements as a comma-seperated string', () => { + xit('returns the array elements as a comma-seperated string', () => { expect(arrayToCSVString(['a', 'b', 'c', 'd'])).toEqual('a,b,c,d'); expect(arrayToCSVString([1, 2, 3, 4, 5])).toEqual('1,2,3,4,5'); }); }); describe('csvStringToArray', () => { - it('converts the csv string as an array', () => { + xit('converts the csv string as an array', () => { expect(csvStringToArray('a,b,c,d')).toEqual(['a', 'b', 'c', 'd']); expect(csvStringToArray('1,2,3,4,5')).toEqual(['1', '2', '3', '4', '5']); }); }); describe('addToArray', () => { - it('adds the item to the end of the array', () => { + xit('adds the item to the end of the array', () => { const array = []; const array2 = [1, 2, 3]; @@ -59,7 +59,7 @@ describe('addToArray', () => { }); describe('addToArray2', () => { - it('returns a new array with the value appended', () => { + xit('returns a new array with the value appended', () => { const array = ['a', 'b', 'c']; const array2 = [1, 2, 3]; @@ -72,7 +72,7 @@ describe('addToArray2', () => { }); describe('removeNthElement', () => { - it('removes the element at position n', () => { + xit('removes the element at position n', () => { const array = ['ant', 'bison', 'cockerel', 'duck', 'elephant']; removeNthElement(2, array); expect(array).toEqual(['ant', 'bison', 'duck', 'elephant']); @@ -84,7 +84,7 @@ describe('removeNthElement', () => { }); describe('numbersToStrings', () => { - it('converts every number in the array to a string', () => { + xit('converts every number in the array to a string', () => { expect(numbersToStrings([1, 2, 3])).toEqual(['1', '2', '3']); expect(numbersToStrings([7, 8, 9])).toEqual(['7', '8', '9']); }); @@ -221,7 +221,7 @@ describe('elementsStartingWithAVowel', () => { }); describe('removeSpaces', () => { - xit('returns the string with the space characters removed', () => { + it('returns the string with the space characters removed', () => { expect(removeSpaces('this string has spaces')).toEqual( 'thisstringhasspaces' ); diff --git a/src/arrays.js b/src/arrays.js index ef6422b..1f39ffc 100644 --- a/src/arrays.js +++ b/src/arrays.js @@ -58,7 +58,8 @@ const elementsStartingWithAVowel = strings => { }; const removeSpaces = string => { - // your code here + return string.replace(/\s/g,'') + }; const sumNumbers = numbers => { From 52fa71618035c2b90362e36ffffbd0e9cc7d5fa2 Mon Sep 17 00:00:00 2001 From: AJ Lobb Date: Tue, 1 Mar 2022 10:06:54 +0000 Subject: [PATCH 22/22] created code and tested for onlyEven --- src/__tests__/arrays.test.js | 4 ++-- src/arrays.js | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/__tests__/arrays.test.js b/src/__tests__/arrays.test.js index 9626efe..ed0ac6f 100644 --- a/src/__tests__/arrays.test.js +++ b/src/__tests__/arrays.test.js @@ -121,7 +121,7 @@ describe('reverseWordsInArray', () => { }); describe('onlyEven', () => { - xit('filters the array and only returns even numbers', () => { + it('filters the array and only returns even numbers', () => { expect(onlyEven([1, 2, 3, 4, 5, 6, 7, 8])).toEqual([2, 4, 6, 8]); expect(onlyEven([8, 9, 10, 11, 12, 13, 14, 15])).toEqual([8, 10, 12, 14]); }); @@ -221,7 +221,7 @@ describe('elementsStartingWithAVowel', () => { }); describe('removeSpaces', () => { - it('returns the string with the space characters removed', () => { + xit('returns the string with the space characters removed', () => { expect(removeSpaces('this string has spaces')).toEqual( 'thisstringhasspaces' ); diff --git a/src/arrays.js b/src/arrays.js index 1f39ffc..f6f7255 100644 --- a/src/arrays.js +++ b/src/arrays.js @@ -46,7 +46,10 @@ const reverseWordsInArray = strings => { }; const onlyEven = numbers => { - // your code here + const even = numbers.filter(number => { + return number % 2 ===0; + }) + return even }; const removeNthElement2 = (index, array) => {