From 61519f89e68341dfc4d558e41f4fd1d821760534 Mon Sep 17 00:00:00 2001 From: Shaun Emery Date: Mon, 22 Nov 2021 12:56:26 +0000 Subject: [PATCH 01/13] add and subtract exercises done --- src/__tests__/numbers.test.js | 4 ++-- src/numbers.js | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/__tests__/numbers.test.js b/src/__tests__/numbers.test.js index 253de15f..b740cdd2 100644 --- a/src/__tests__/numbers.test.js +++ b/src/__tests__/numbers.test.js @@ -13,7 +13,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); @@ -22,7 +22,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); diff --git a/src/numbers.js b/src/numbers.js index d3eab646..7029f454 100644 --- a/src/numbers.js +++ b/src/numbers.js @@ -1,9 +1,11 @@ -function add (a, b) { - // your code here -} + + const add = (a, b) => { + return a + b; + }; + function subtract (a, b) { - // your code here + return a-b; } function multiply (a, b) { From 57b0cd0ca2461039199779f506f502def2978442 Mon Sep 17 00:00:00 2001 From: Shaun Emery Date: Mon, 22 Nov 2021 13:00:23 +0000 Subject: [PATCH 02/13] add and subtract exercises done --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dc2529d3..40b8c430 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ }, "homepage": "https://github.com/MCRcodes/javascript-basics#readme", "devDependencies": { - "eslint": "^6.5.1", + "eslint": "^8.3.0", "eslint-config-airbnb-base": "^14.0.0", "eslint-config-prettier": "^6.4.0", "eslint-plugin-import": "^2.18.2", From 3121df6a1e7b562bc7188adf4abd6473f1668bf9 Mon Sep 17 00:00:00 2001 From: Shaun Emery Date: Mon, 22 Nov 2021 13:09:50 +0000 Subject: [PATCH 03/13] third number exercise --- src/__tests__/numbers.test.js | 2 +- src/numbers.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/__tests__/numbers.test.js b/src/__tests__/numbers.test.js index b740cdd2..66b1f93c 100644 --- a/src/__tests__/numbers.test.js +++ b/src/__tests__/numbers.test.js @@ -32,7 +32,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); diff --git a/src/numbers.js b/src/numbers.js index 7029f454..62310e9e 100644 --- a/src/numbers.js +++ b/src/numbers.js @@ -9,7 +9,7 @@ function subtract (a, b) { } function multiply (a, b) { - // your code here + return a*b; } function divide (a, b) { From 5880f242489d1b19462ca60eae7d491438378a1e Mon Sep 17 00:00:00 2001 From: Shaun Emery Date: Mon, 22 Nov 2021 15:03:44 +0000 Subject: [PATCH 04/13] numbers exercise complete --- src/__tests__/numbers.test.js | 16 ++++++++-------- src/numbers.js | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/__tests__/numbers.test.js b/src/__tests__/numbers.test.js index 66b1f93c..d610b3b3 100644 --- a/src/__tests__/numbers.test.js +++ b/src/__tests__/numbers.test.js @@ -40,7 +40,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); @@ -49,7 +49,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); @@ -57,7 +57,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); @@ -65,7 +65,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); @@ -73,7 +73,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); @@ -81,7 +81,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); @@ -93,7 +93,7 @@ describe('quotient', () => { // the first by the second, without the remainder // 18 divided by 7 is 2 remainder 4 (or 2.571...) // so the quotient of 18 and 7 is 2 - xit('returns the quotient from dividing the first number by the second number', () => { + it('returns the quotient from dividing the first number by the second number', () => { expect(quotient(10, 3)).toEqual(3); expect(quotient(18, 7)).toEqual(2); expect(quotient(77, 10)).toEqual(7); @@ -102,7 +102,7 @@ describe('quotient', () => { }); describe('remainder', () => { - xit('returns the remainder when dividing the first number by the second number', () => { + it('returns the remainder when dividing the first number by the second number', () => { expect(remainder(10, 3)).toEqual(1); expect(remainder(18, 7)).toEqual(4); expect(remainder(77, 10)).toEqual(7); diff --git a/src/numbers.js b/src/numbers.js index 62310e9e..30e363d0 100644 --- a/src/numbers.js +++ b/src/numbers.js @@ -13,35 +13,35 @@ function multiply (a, b) { } function divide (a, b) { - // your code here + return a/b; } function power (a, b) { - // your code here + return 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); } function quotient (a, b) { - // your code here + return ~~(a/b); } function remainder (a, b) { - // your code here + return a % b; } module.exports = { From e66ef1e96a7d285b55dfe905598fb71afc0272fc Mon Sep 17 00:00:00 2001 From: Shaun Emery Date: Tue, 23 Nov 2021 09:06:22 +0000 Subject: [PATCH 05/13] completed string section --- src/__tests__/strings.test.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/__tests__/strings.test.js b/src/__tests__/strings.test.js index e2c3c887..b19fd739 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'); }); }); From aa859fe1cabdd362feeab19517be586d7660e737 Mon Sep 17 00:00:00 2001 From: Shaun Emery Date: Tue, 23 Nov 2021 10:13:50 +0000 Subject: [PATCH 06/13] halfway through boolean --- src/__tests__/booleans.test.js | 22 +++++++++++----------- src/booleans.js | 24 ++++++++++++++---------- src/strings.js | 14 ++++++++------ 3 files changed, 33 insertions(+), 27 deletions(-) diff --git a/src/__tests__/booleans.test.js b/src/__tests__/booleans.test.js index df9b6c0e..257b3e8a 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 values are true', () => { + it('returns true if both of the given values 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 values are true', () => { + it('returns true if at least one of the given values 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 values are true', () => { + it('returns true if neither of the given values 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 values are true', () => { + it('returns true if exactly one of the given values 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); @@ -85,7 +85,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); @@ -93,7 +93,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); @@ -101,7 +101,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); @@ -110,7 +110,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); diff --git a/src/booleans.js b/src/booleans.js index 5ff6cb55..f4120f85 100644 --- a/src/booleans.js +++ b/src/booleans.js @@ -1,17 +1,17 @@ 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); }; function one(a, b) { @@ -19,27 +19,31 @@ function one(a, b) { }; function truthiness(a) { - // your code here + return Boolean(a); }; 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 true; + } }; function isEven(a) { - // your code here + if (a%2 === 0) { + return true; + } }; function isSquare(a) { diff --git a/src/strings.js b/src/strings.js index ce02affa..c0acb616 100644 --- a/src/strings.js +++ b/src/strings.js @@ -1,25 +1,27 @@ 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[0]; }; function firstCharacters (string, n) { - // your code here + return string.substring(0, n); }; module.exports = { From 1a06f5668794baffc59236a84d8adcd24445ef9f Mon Sep 17 00:00:00 2001 From: Shaun Emery Date: Tue, 23 Nov 2021 13:46:53 +0000 Subject: [PATCH 07/13] two boolean to go --- src/__tests__/booleans.test.js | 8 ++++---- src/booleans.js | 19 +++++++++++++------ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/__tests__/booleans.test.js b/src/__tests__/booleans.test.js index 257b3e8a..840c2860 100644 --- a/src/__tests__/booleans.test.js +++ b/src/__tests__/booleans.test.js @@ -119,7 +119,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(5)).toEqual(false); expect(isSquare(-4)).toEqual(false); @@ -128,7 +128,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('a', 'qaardvark')).toBe(false); expect(startsWith('a', 'Aardvark')).toBe(false); @@ -136,7 +136,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); @@ -144,7 +144,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/booleans.js b/src/booleans.js index f4120f85..0d4ccab2 100644 --- a/src/booleans.js +++ b/src/booleans.js @@ -15,7 +15,9 @@ function none(a, b) { }; function one(a, b) { - // your code here + if ((a === true && b === false) || (a === false && b === true)) { + return true; + } else return false; }; function truthiness(a) { @@ -35,23 +37,28 @@ function isLessThanOrEqualTo(a, b) { }; function isOdd(a) { - if (a%2 !== 0){ + if (a%2 !== 0) { return true; - } + } else return false; }; function isEven(a) { if (a%2 === 0) { return true; - } + } else return false; }; function isSquare(a) { - // your code here + if (Number.isInteger(Math.sqrt(a))){ + return true; + } else return false; + }; function startsWith(char, string) { - // your code here + if (string[0] === char){ + return true; + } else return false; }; function containsVowels(string) { From 991546f29fbfe2b68fcf79ec5482f834979666ce Mon Sep 17 00:00:00 2001 From: Shaun Emery Date: Tue, 23 Nov 2021 16:32:19 +0000 Subject: [PATCH 08/13] 14 out of 15 boolean complete --- src/booleans.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/booleans.js b/src/booleans.js index 0d4ccab2..86b65e77 100644 --- a/src/booleans.js +++ b/src/booleans.js @@ -1,9 +1,10 @@ +/* eslint-disable no-unreachable */ function negate(a) { return !a; }; function both(a, b) { - return (a && b); + return a && b; }; function either(a, b) { @@ -62,7 +63,16 @@ function startsWith(char, string) { }; function containsVowels(string) { - // your code here + let string2 = string.toLowerCase(); + let value = false + for (let i=0; i Date: Tue, 23 Nov 2021 19:48:59 +0000 Subject: [PATCH 09/13] complete boolean --- src/booleans.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/booleans.js b/src/booleans.js index 86b65e77..69968e90 100644 --- a/src/booleans.js +++ b/src/booleans.js @@ -64,6 +64,7 @@ function startsWith(char, string) { function containsVowels(string) { let string2 = string.toLowerCase(); + console.log(string2); let value = false for (let i=0; i Date: Wed, 24 Nov 2021 10:33:36 +0000 Subject: [PATCH 10/13] 2nd array exercise complete --- src/__tests__/arrays.test.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/__tests__/arrays.test.js b/src/__tests__/arrays.test.js index aaf10af1..fa59b25d 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]; From d6fb58cabe43f1f4f20082b7e6f39d4cc1848d0d Mon Sep 17 00:00:00 2001 From: Shaun Emery Date: Wed, 24 Nov 2021 12:39:44 +0000 Subject: [PATCH 11/13] 8 array exercises done --- src/__tests__/arrays.test.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/__tests__/arrays.test.js b/src/__tests__/arrays.test.js index fa59b25d..1e669a57 100644 --- a/src/__tests__/arrays.test.js +++ b/src/__tests__/arrays.test.js @@ -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']); @@ -80,13 +80,13 @@ 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']); }); }); describe('uppercaseWordsInArray', () => { - xit('makes every string in the array uppercase', () => { + it('makes every string in the array uppercase', () => { expect(uppercaseWordsInArray(['cat', 'mouse', 'banana'])).toEqual([ 'CAT', 'MOUSE', @@ -96,7 +96,7 @@ describe('uppercaseWordsInArray', () => { }); describe('reverseWordsInArray', () => { - xit('reverses every string in an array', () => { + it('reverses every string in an array', () => { expect(reverseWordsInArray(['cat', 'Mouse', 'banana'])).toEqual([ 'tac', 'esuoM', From 83285dab90c5d0aa1b09e1f3031a53f7b31a45d2 Mon Sep 17 00:00:00 2001 From: Shaun Emery Date: Wed, 24 Nov 2021 14:50:36 +0000 Subject: [PATCH 12/13] starts with vowel complete --- src/__tests__/arrays.test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/__tests__/arrays.test.js b/src/__tests__/arrays.test.js index 1e669a57..76d91a30 100644 --- a/src/__tests__/arrays.test.js +++ b/src/__tests__/arrays.test.js @@ -106,13 +106,13 @@ 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]); }); }); describe('removeNthElement2', () => { - xit('returns an array with the nth element removed, and does not mutate the original', () => { + it('returns an array with the nth element removed, and does not mutate the original', () => { const array = ['bike', 'car', 'train', 'bus']; expect(removeNthElement2(2, array)).toEqual(['bike', 'car', 'bus']); expect(array).toEqual(['bike', 'car', 'train', 'bus']); @@ -120,7 +120,7 @@ describe('removeNthElement2', () => { }); describe('elementsStartingWithAVowel', () => { - xit('returns elements starting with a vowel', () => { + it('returns elements starting with a vowel', () => { expect( elementsStartingWithAVowel([ 'apple', @@ -153,7 +153,7 @@ describe('elementsStartingWithAVowel', () => { ).toEqual(['apple', 'epple', 'ipple', 'opple', 'upple']); }); - xit('is case insensitive', () => { + it('is case insensitive', () => { expect( elementsStartingWithAVowel([ 'Apple', From c0c5744bf21227b517651a7fdfca669c3d950c89 Mon Sep 17 00:00:00 2001 From: Shaun Emery Date: Fri, 26 Nov 2021 09:23:08 +0000 Subject: [PATCH 13/13] space exercise complete --- src/__tests__/arrays.test.js | 2 +- src/arrays.js | 81 +++++++++++++++++++++++++++++------- src/booleans.js | 1 - 3 files changed, 68 insertions(+), 16 deletions(-) diff --git a/src/__tests__/arrays.test.js b/src/__tests__/arrays.test.js index 76d91a30..3f89824a 100644 --- a/src/__tests__/arrays.test.js +++ b/src/__tests__/arrays.test.js @@ -188,7 +188,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 822c49b7..0c9bf599 100644 --- a/src/arrays.js +++ b/src/arrays.js @@ -1,9 +1,17 @@ + const getNthElement = (index, array) => { - // your code here + return array[index%array.length]; }; const arrayToCSVString = array => { - // your code here + let newArray = ''; + for (let i = 0; i { @@ -11,43 +19,88 @@ const csvStringToArray = string => { }; const addToArray = (element, array) => { - // your code here + array.push(element); }; const addToArray2 = (element, array) => { - // your code here -}; + const newArray = array; + let x = newArray.push(element); +} const removeNthElement = (index, array) => { - // your code here + let array2=array.splice(index, 1); + + }; const numbersToStrings = numbers => { - // your code here + for (let i = 0; i < numbers.length; i++) { + numbers[i] = numbers[i].toString(); + } + return numbers; }; const uppercaseWordsInArray = strings => { - // your code here + for (let i = 0; i { - // your code here + let reverseArray =[]; + for (i = 0; i < strings.length; i++) { + let reverseString = ''; + let word = strings[i]; + for (j = word.length - 1; j >= 0; j--) { + reverseString += word[j]; + } + reverseArray.push(reverseString); + } + return reverseArray; }; const onlyEven = numbers => { - // your code here + console.log(numbers); + let newArray=[]; + for (let i = 0; i < numbers.length; i++) { + if (numbers[i]%2 === 0) { + console.log(i, numbers[i]); + newArray.push(numbers[i]); + }; + } + console.log(newArray); + return newArray; }; const removeNthElement2 = (index, array) => { - // your code here + let newArray = array.slice(index); + console.log(array, newArray); + return array; }; const elementsStartingWithAVowel = strings => { - // your code here + let newArray = []; + for (let i = 0; i< strings.length; i++) { + let x = strings[i].toLowerCase(); + if (x.startsWith('a') || (x.startsWith('e')) || (x.startsWith('i')) || + (x.startsWith('o')) || (x.startsWith('u'))) { + newArray.push(strings[i]); + } + + }; + return newArray; }; + const removeSpaces = string => { - // your code here + let newString = ''; + for (let i = 0; i { @@ -74,4 +127,4 @@ module.exports = { removeSpaces, sumNumbers, sortByLastLetter -}; +}; \ No newline at end of file diff --git a/src/booleans.js b/src/booleans.js index 69968e90..131fcce7 100644 --- a/src/booleans.js +++ b/src/booleans.js @@ -64,7 +64,6 @@ function startsWith(char, string) { function containsVowels(string) { let string2 = string.toLowerCase(); - console.log(string2); let value = false for (let i=0; i