From 7b8126728aff18eb2f58b40b6b98e66de5200402 Mon Sep 17 00:00:00 2001 From: July Moss Date: Wed, 24 Nov 2021 08:04:17 +0000 Subject: [PATCH 1/8] completed strings.js test --- src/strings.js | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/strings.js b/src/strings.js index ce02affa..de46c38d 100644 --- a/src/strings.js +++ b/src/strings.js @@ -1,25 +1,37 @@ -function sayHello (string) { - // your code here +const sayHello = (word) => { + if (typeof word === 'string'){ + return 'Hello, ' + word + '!'; + } }; -function uppercase (string) { - // your code here +const uppercase = (upperWord) => { + if (typeof upperWord === 'string'){ + return upperWord.toUpperCase(); + } }; -function lowercase (string) { - // your code here +const lowercase = (lowerWord) => { + if (typeof lowerWord === 'string'){ + return lowerWord.toLowerCase(); + } }; -function countCharacters (string) { - // your code here +const countCharacters = (countWord) => { + if (typeof countWord === 'string'){ + return countWord.length; + } }; -function firstCharacter (string) { - // your code here +const firstCharacter = (firstAlp) => { + if (typeof firstAlp === 'string'){ + return firstAlp[0]; + } }; -function firstCharacters (string, n) { - // your code here +const firstCharacters = (string, n) => { + if (typeof string === 'string'){ + return string.slice(0, n); + } }; module.exports = { From 33625c238c4f1a7069000308fffb16082f8af5b4 Mon Sep 17 00:00:00 2001 From: July Moss Date: Wed, 24 Nov 2021 09:03:13 +0000 Subject: [PATCH 2/8] completed numbers.js test --- src/numbers.js | 99 +++++++++++++++++++++++++++++++------------------- 1 file changed, 61 insertions(+), 38 deletions(-) diff --git a/src/numbers.js b/src/numbers.js index d3eab646..a0ece0b2 100644 --- a/src/numbers.js +++ b/src/numbers.js @@ -1,57 +1,80 @@ -function add (a, b) { - // your code here -} +const add = (a, b) => { + if (typeof a === 'number' && typeof b === 'number'){ + return a + b; + } +}; -function subtract (a, b) { - // your code here -} +const subtract = (a, b) => { + if (typeof a === 'number' && typeof b === 'number'){ + return a - b; + } +}; -function multiply (a, b) { - // your code here +const multiply = (a, b) => { + if (typeof a === 'number' && typeof b === 'number'){ + return a * b; + } +}; +const divide = (a, b) => { + if (typeof a === 'number' && typeof b === 'number'){ + return a / b; + } } -function divide (a, b) { - // your code here +const power = (a, b) => { + if (typeof a === 'number' && typeof b === 'number'){ + return a ** b; + } } -function power (a, b) { - // your code here +const round = (a) => { + if (typeof a === 'number'){ + return Math.round(a); + } } -function round (a) { - // your code here +const roundUp = (a) => { + if (typeof a === 'number'){ + return Math.ceil(a); + } } -function roundUp (a) { - // your code here +const roundDown = (a) => { + if (typeof a === 'number'){ + return Math.floor(a); + } } -function roundDown (a) { - // your code here +const absolute = (a) => { + if (typeof a === 'number'){ + return Math.abs(a); + } } -function absolute (a) { - // your code here +const quotient = (a, b) => { + if (typeof a === 'number' && typeof b === 'number' && a >= 0){ + return Math.floor(a / b); + }else if (typeof a === 'number' && typeof b === 'number' && a < 0){ + return Math.ceil(a / b); + } } -function quotient (a, b) { - // your code here -} - -function remainder (a, b) { - // your code here +const remainder = (a, b) => { + if (typeof a === 'number' && typeof b === 'number'){ + return a % b; + } } module.exports = { - add, - subtract, - multiply, - divide, - power, - round, - roundUp, - roundDown, - absolute, - quotient, - remainder -} +add, +subtract, +multiply, +divide, +power, +round, +roundUp, +roundDown, +absolute, +quotient, +remainder +} \ No newline at end of file From 0b71e58e2681112e19f462beb7d0e360e46ee25a Mon Sep 17 00:00:00 2001 From: July Moss Date: Fri, 26 Nov 2021 13:21:24 +0000 Subject: [PATCH 3/8] completed booleans.js test --- src/booleans.js | 133 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 103 insertions(+), 30 deletions(-) diff --git a/src/booleans.js b/src/booleans.js index 5ff6cb55..ca25c383 100644 --- a/src/booleans.js +++ b/src/booleans.js @@ -1,61 +1,134 @@ -function negate(a) { - // your code here +const negate = (a) => { + if (typeof a === 'boolean'){ + return !a; + } }; -function both(a, b) { - // your code here +const both = (a, b) => { + if (a === true && b === true){ + return true; + }else if(a === true && b === false){ + return false; + }else if (a === false && b === true){ + return false; + }else{ + return false; + } }; -function either(a, b) { - // your code here +const either = (a, b) => { + if (a === true || b === true){ + return true; + }else if (a === false || b === false){ + return false; + } }; -function none(a, b) { - // your code here +const none = (a, b) => { + if (a === true && b === true){ + return false; + }else if(a === true && b === false){ + return false; + }else if (a === false && b === true){ + return false; + }else{ + return true; + } }; -function one(a, b) { - // your code here +const one = (a, b) => { + if (a === true && b === true){ + return false; + }else if(a === true && b === false){ + return true; + }else if (a === false && b === true){ + return true; + }else{ + return false; + } }; -function truthiness(a) { - // your code here +const truthiness = (a) => { + if(a){ + return true; + }else{ + return false; + } }; -function isEqual(a, b) { - // your code here +const isEqual = (a, b) => { + if (a === b){ + return true; + }else{ + return false; + } }; -function isGreaterThan(a, b) { - // your code here +const isGreaterThan = (a, b) => { + if (a > b){ + return true; + }else{ + return false; + } }; -function isLessThanOrEqualTo(a, b) { - // your code here +const isLessThanOrEqualTo = (a, b) => { + if (a <= b){ + return true; + }else{ + return false; + } }; -function isOdd(a) { - // your code here +const isOdd = (a) => { + if (a % 2 === 1){ + return true; + }else{ + return false; + } }; -function isEven(a) { - // your code here +const isEven = (a) => { + if (a % 2 === 0){ + return true; + }else{ + return false; + } }; -function isSquare(a) { - // your code here +const isSquare = (a) => { + if (a >=0 && Math.sqrt(a) % 1 === 0){ + return true; + }else{ + return false; + } }; -function startsWith(char, string) { - // your code here +const startsWith = (char, string) => { + if (string.startsWith(char) === true){ + return true; + }else{ + return false; + } }; -function containsVowels(string) { - // your code here +const containsVowels = (string) => { + const vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]; + + for (let i = 0; i < string.length; i++){ + if (vowels.includes(string[i])){ + return true; + } + } + return false; }; -function isLowerCase(string) { - // your code here +const isLowerCase = (string) => { + if (string === string.toLowerCase()){ + return true; + }else{ + return false; + } }; module.exports = { From 88a8c68fca690456f26aa41f8ddf2da33a521edf Mon Sep 17 00:00:00 2001 From: July Moss Date: Mon, 29 Nov 2021 23:07:37 +0000 Subject: [PATCH 4/8] completed arrays.js test --- src/arrays.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/arrays.js b/src/arrays.js index 822c49b7..564581a1 100644 --- a/src/arrays.js +++ b/src/arrays.js @@ -1,61 +1,79 @@ +const array = ['cat', 'dog', 'elephant', 'fox']; const getNthElement = (index, array) => { - // your code here + return array[index % array.length]; }; + const arrayToCSVString = array => { // your code here + return array.toString(); }; const csvStringToArray = string => { // your code here + return string.split(','); }; const addToArray = (element, array) => { // your code here + console.log(array.push(element)); }; const addToArray2 = (element, array) => { // your code here + return array.concat(element); }; const removeNthElement = (index, array) => { // your code here + return array.splice(index, 1); }; const numbersToStrings = numbers => { // your code here + return numbers.map(String); }; const uppercaseWordsInArray = strings => { // your code here + return strings.map(string => string.toUpperCase()); }; const reverseWordsInArray = strings => { // your code here + return strings.map(string => string.split('').reverse().join('')); }; const onlyEven = numbers => { // your code here + return numbers.filter(x => x % 2 === 0); }; const removeNthElement2 = (index, array) => { // your code here -}; + const newArray = [...array]; + newArray.splice(index, 1); + return newArray; +} const elementsStartingWithAVowel = strings => { // your code here -}; + return strings.filter(string => (string.match(/^[aeiou]/gi))); +} const removeSpaces = string => { // your code here + return string.replace(/\s+/g, ''); }; const sumNumbers = numbers => { // your code here + return numbers.reduce((total, current) => total + current, 0) }; const sortByLastLetter = strings => { // your code here + return strings.sort((x, y) => x.charCodeAt(x.length - 1) - y.charCodeAt(y.length - 1)); }; module.exports = { From 7900057d64ed03a866f0a83949ed4013f85d629b Mon Sep 17 00:00:00 2001 From: July Moss Date: Tue, 30 Nov 2021 00:09:15 +0000 Subject: [PATCH 5/8] completed objects.js test --- src/objects.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/objects.js b/src/objects.js index 906eef8f..3137721d 100644 --- a/src/objects.js +++ b/src/objects.js @@ -1,41 +1,59 @@ const createPerson = (name, age) => { // your code here + this.name = name; + this.age = age; + return this; }; const getName = object => { // your code here + return object.name; }; const getProperty = (property, object) => { // your code here + return object[property]; }; const hasProperty = (property, object) => { // your code here + return object[property]? true : false; }; const isOver65 = person => { // your code here + return person.age > 65? true : false; }; const getAges = people => { // your code here + return people.map(ageArray => ageArray.age); }; const findByName = (name, people) => { // your code here + return people.find(person => person.name === name); }; const findHondas = cars => { // your code here + return cars.filter(carModel => carModel.manufacturer === 'Honda'); }; const averageAge = people => { // your code here + return people.reduce((a,b) => a + b.age, 0) / people.length; }; const createTalkingPerson = (name, age) => { // your code here + return { + name: name, + age: age, + introduce: stranger => { + return `Hi ${stranger}, my name is ${name} and I am ${age}!`; + } + }; }; module.exports = { From 6eafa751fa22b7be77e9331dae57ac4542333aa1 Mon Sep 17 00:00:00 2001 From: July Moss Date: Tue, 30 Nov 2021 00:17:07 +0000 Subject: [PATCH 6/8] refactored numbers.js --- src/numbers.js | 69 +++++++++----------------------------------------- 1 file changed, 12 insertions(+), 57 deletions(-) diff --git a/src/numbers.js b/src/numbers.js index a0ece0b2..a06be0e0 100644 --- a/src/numbers.js +++ b/src/numbers.js @@ -1,69 +1,24 @@ -const add = (a, b) => { - if (typeof a === 'number' && typeof b === 'number'){ - return a + b; - } -}; +const add = (a, b) => a + b; -const subtract = (a, b) => { - if (typeof a === 'number' && typeof b === 'number'){ - return a - b; - } -}; +const subtract = (a, b) => a - b; -const multiply = (a, b) => { - if (typeof a === 'number' && typeof b === 'number'){ - return a * b; - } -}; -const divide = (a, b) => { - if (typeof a === 'number' && typeof b === 'number'){ - return a / b; - } -} +const multiply = (a, b) => a * b; -const power = (a, b) => { - if (typeof a === 'number' && typeof b === 'number'){ - return a ** b; - } -} +const divide = (a, b) => a / b; -const round = (a) => { - if (typeof a === 'number'){ - return Math.round(a); - } -} +const power = (a, b) => a ** b; -const roundUp = (a) => { - if (typeof a === 'number'){ - return Math.ceil(a); - } -} +const round = (a) => Math.round(a); -const roundDown = (a) => { - if (typeof a === 'number'){ - return Math.floor(a); - } -} +const roundUp = (a) => Math.ceil(a); -const absolute = (a) => { - if (typeof a === 'number'){ - return Math.abs(a); - } -} +const roundDown = (a) => Math.floor(a); -const quotient = (a, b) => { - if (typeof a === 'number' && typeof b === 'number' && a >= 0){ - return Math.floor(a / b); - }else if (typeof a === 'number' && typeof b === 'number' && a < 0){ - return Math.ceil(a / b); - } -} +const absolute = (a) => Math.abs(a); -const remainder = (a, b) => { - if (typeof a === 'number' && typeof b === 'number'){ - return a % b; - } -} +const quotient = (a, b) => Math.trunc(a / b); + +const remainder = (a, b) => a % b; module.exports = { add, From d9f98111caeae49b05f596bd08be6d4a49e7d95b Mon Sep 17 00:00:00 2001 From: July Moss Date: Tue, 30 Nov 2021 00:21:15 +0000 Subject: [PATCH 7/8] refactored strings.js --- src/strings.js | 36 ++++++------------------------------ 1 file changed, 6 insertions(+), 30 deletions(-) diff --git a/src/strings.js b/src/strings.js index de46c38d..84e11fe5 100644 --- a/src/strings.js +++ b/src/strings.js @@ -1,38 +1,14 @@ -const sayHello = (word) => { - if (typeof word === 'string'){ - return 'Hello, ' + word + '!'; - } -}; +const sayHello = (string) => `Hello, ${string}!`; -const uppercase = (upperWord) => { - if (typeof upperWord === 'string'){ - return upperWord.toUpperCase(); - } -}; +const uppercase = (upperWord) => upperWord.toUpperCase(); -const lowercase = (lowerWord) => { - if (typeof lowerWord === 'string'){ - return lowerWord.toLowerCase(); - } -}; +const lowercase = (lowerWord) => lowerWord.toLowerCase(); -const countCharacters = (countWord) => { - if (typeof countWord === 'string'){ - return countWord.length; - } -}; +const countCharacters = (countWord) => countWord.length; -const firstCharacter = (firstAlp) => { - if (typeof firstAlp === 'string'){ - return firstAlp[0]; - } -}; +const firstCharacter = (firstAlp) => firstAlp[0]; -const firstCharacters = (string, n) => { - if (typeof string === 'string'){ - return string.slice(0, n); - } -}; +const firstCharacters = (string, n) => string.slice(0, n); module.exports = { sayHello, From 8c785c5a2415ab44901cad004554286173b2af20 Mon Sep 17 00:00:00 2001 From: July Moss Date: Tue, 30 Nov 2021 00:34:40 +0000 Subject: [PATCH 8/8] refactored booleans.js --- src/booleans.js | 89 +++++++++++++++---------------------------------- 1 file changed, 26 insertions(+), 63 deletions(-) diff --git a/src/booleans.js b/src/booleans.js index ca25c383..4418f7dc 100644 --- a/src/booleans.js +++ b/src/booleans.js @@ -1,135 +1,98 @@ -const negate = (a) => { - if (typeof a === 'boolean'){ - return !a; - } -}; +const negate = (a) => !a; const both = (a, b) => { - if (a === true && b === true){ - return true; - }else if(a === true && b === false){ - return false; - }else if (a === false && b === true){ - return false; - }else{ + if (!a || !b) { return false; } -}; + return true; +} const either = (a, b) => { - if (a === true || b === true){ + if (a || b) { return true; - }else if (a === false || b === false){ - return false; } -}; - + return false; +} const none = (a, b) => { - if (a === true && b === true){ - return false; - }else if(a === true && b === false){ + if (a || b) { return false; - }else if (a === false && b === true){ - return false; - }else{ - return true; } -}; + return true; +} const one = (a, b) => { - if (a === true && b === true){ - return false; - }else if(a === true && b === false){ - return true; - }else if (a === false && b === true){ + if ((a && !b) || (b && !a)) { return true; - }else{ - return false; } -}; + return false; +} const truthiness = (a) => { if(a){ return true; - }else{ + } return false; } -}; const isEqual = (a, b) => { if (a === b){ return true; - }else{ + } return false; } -}; + const isGreaterThan = (a, b) => { if (a > b){ return true; - }else{ + } return false; } -}; const isLessThanOrEqualTo = (a, b) => { if (a <= b){ return true; - }else{ + } return false; } -}; const isOdd = (a) => { if (a % 2 === 1){ return true; - }else{ + } return false; } -}; const isEven = (a) => { if (a % 2 === 0){ return true; - }else{ + } return false; } -}; const isSquare = (a) => { - if (a >=0 && Math.sqrt(a) % 1 === 0){ + if (Math.sqrt(a) % 1 === 0){ return true; - }else{ + } return false; } -}; const startsWith = (char, string) => { if (string.startsWith(char) === true){ return true; - }else{ + } return false; } -}; -const containsVowels = (string) => { - const vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]; - - for (let i = 0; i < string.length; i++){ - if (vowels.includes(string[i])){ - return true; - } - } - return false; -}; + +const containsVowels = (string) => /[aeiou]/gi.test(string); const isLowerCase = (string) => { if (string === string.toLowerCase()){ return true; - }else{ + } return false; } -}; module.exports = { negate,