diff --git a/src/__tests__/booleans.test.js b/src/__tests__/booleans.test.js index 734201d5..d6477555 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 253de15f..d610b3b3 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); @@ -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); @@ -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/__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'); }); }); diff --git a/src/arrays.js b/src/arrays.js index 822c49b7..2405bf20 100644 --- a/src/arrays.js +++ b/src/arrays.js @@ -1,61 +1,75 @@ const getNthElement = (index, array) => { - // your code here + +return array[index % array.length] + }; + 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 count= array.push(element); +console.log(array); }; const addToArray2 = (element, array) => { - // your code here +return array.concat(element); + }; const removeNthElement = (index, array) => { - // your code here + array.splice(index, 1); + console.log(array); }; const numbersToStrings = numbers => { - // your code here +return numbers.map(String); }; const uppercaseWordsInArray = strings => { - // your code here + return strings.map(function(x){return x.toUpperCase();}) }; const reverseWordsInArray = strings => { - // your code here +return strings.map(string=> string.split("").reverse().join("")); }; + const onlyEven = numbers => { - // your code here + const onlyEven = numbers.filter(number => number % 2===0); +return onlyEven; }; const removeNthElement2 = (index, array) => { - // your code here +const NthElement2 = [...array]; + NthElement2.splice(index, 1); + return NthElement2; }; const elementsStartingWithAVowel = strings => { - // your code here + + return strings.filter(strings=> /^[aeiou]/gi.test(strings)); }; const removeSpaces = string => { - // your code here + return string.split(" ").join(""); }; const sumNumbers = numbers => { - // your code here -}; +return sum = numbers.reduce((acc, number) => (acc + number)); + + }; const sortByLastLetter = strings => { - // your code here + return strings.sort((a,b)=> a.charCodeAt(a.length-1)- b.charCodeAt(b.length-1)); + + }; module.exports = { diff --git a/src/booleans.js b/src/booleans.js index 5ff6cb55..e0f3ba6f 100644 --- a/src/booleans.js +++ b/src/booleans.js @@ -1,61 +1,67 @@ function negate(a) { - // your code here + return a= !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) { - // your code here + return a===!b; }; function truthiness(a) { - // your code here + return (!!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 -}; + return (a%2>0); +} function isEven(a) { - // your code here + return (a%2===0); }; function isSquare(a) { - // your code here -}; + if (a>=0) { + let sr = Math.sqrt(a); + return((sr*sr)==a); + } + return false; + } function startsWith(char, string) { - // your code here + return string.startsWith(char); }; function containsVowels(string) { - // your code here + const regex = /[aeiou]/gi +return regex.test(string); }; function isLowerCase(string) { - // your code here + const regex= /([A-Z])/g + return !regex.test(string); }; module.exports = { diff --git a/src/numbers.js b/src/numbers.js index d3eab646..e1e214ed 100644 --- a/src/numbers.js +++ b/src/numbers.js @@ -1,46 +1,46 @@ -function add (a, b) { - // your code here -} +const add = (a, b) => { + return a+b; +}; -function subtract (a, b) { - // your code here -} +const subtract = (a, b) => { + return a-b; +}; -function multiply (a, b) { - // your code here -} +const multiply = (a, b) => { + return a*b; +}; -function divide (a, b) { - // your code here -} +const divide =(a, b) => { + return a/b; +}; -function power (a, b) { - // your code here -} +const power =(a, b) =>{ + return Math.pow (a, b); +}; -function round (a) { - // your code here -} +const round = (a) =>{ + return Math.round(a); +}; -function roundUp (a) { - // your code here -} +const roundUp = (a) =>{ + return Math.ceil(a); +}; -function roundDown (a) { - // your code here -} +const roundDown =(a)=> { + return Math.floor(a); +}; -function absolute (a) { - // your code here -} +const absolute =(a)=> { + return Math.abs(a); +}; -function quotient (a, b) { - // your code here -} +const quotient =(a, b)=> { + return Math.trunc(a/b); +}; -function remainder (a, b) { - // your code here -} +const remainder =(a, b)=> { + return a%b; +}; module.exports = { add, diff --git a/src/strings.js b/src/strings.js index ce02affa..3bc37b78 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 = {