From 67026697cdcf6a2581f7bcaa842f002974da6696 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Sat, 17 Feb 2018 11:42:29 -0600 Subject: [PATCH 01/14] Let's roll! --- src/project-1.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/project-1.js b/src/project-1.js index dc26cfb..51f08e4 100644 --- a/src/project-1.js +++ b/src/project-1.js @@ -2,7 +2,7 @@ const multiplyByTen = (num) => { // return num after multiplying it by ten - // code here + return num * 10; }; const subtractFive = (num) => { From a4a20c94f26e91802198a4a098c3ad0d71ec0ea6 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Sat, 17 Feb 2018 11:45:16 -0600 Subject: [PATCH 02/14] Word to tha' trizzle! --- src/project-1.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/project-1.js b/src/project-1.js index 51f08e4..3c7541d 100644 --- a/src/project-1.js +++ b/src/project-1.js @@ -7,13 +7,13 @@ const multiplyByTen = (num) => { const subtractFive = (num) => { // return num after subtracting five - // code here + return num - 5; }; const areSameLength = (str1, str2) => { // return true if the two strings have the same length // otherwise return false - // code here + return str1.length === str2.length; }; const areEqual = (x, y) => { From 8c7f7518e29ce7fb127803c7d1ce15041dd57c63 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Sat, 17 Feb 2018 12:53:01 -0600 Subject: [PATCH 03/14] This is fun! --- src/project-1.js | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/src/project-1.js b/src/project-1.js index 3c7541d..9502d21 100644 --- a/src/project-1.js +++ b/src/project-1.js @@ -19,121 +19,122 @@ const areSameLength = (str1, str2) => { const areEqual = (x, y) => { // return true if x and y are the same // otherwise return false - // code here + return x === y; }; const lessThanNinety = (num) => { // return true if num is less than ninety // otherwise return false - // code here + return num < 90; }; const greaterThanFifty = (num) => { // return true if num is greater than fifty // otherwise return false - // code here + return num > 50; }; const add = (x, y) => { // add x and y together and return the value - // code here + return x + y; }; const subtract = (x, y) => { // subtract y from x and return the value - // code here + return x - y; }; const divide = (x, y) => { // divide x by y and return the value - // code here + return x / y; }; const multiply = (x, y) => { // multiply x by y and return the value - // code here + return x * y; }; const getRemainder = (x, y) => { // return the remainder from dividing x by y - // code here + return x % y; }; const isEven = (num) => { // return true if num is even // otherwise return false - // code here + return num % 2 === 0; }; const isOdd = (num) => { // return true if num is odd // otherwise return false - // code here + return num % 2 !== 0; }; const square = (num) => { // square num and return the new value - // code here + return num * num; }; const cube = (num) => { // cube num and return the new value - // code here + return num * num * num; }; const raiseToPower = (num, exponent) => { // raise num to whatever power is passed in as exponent - // code here + return Math.pow(num, exponent); }; const roundNumber = (num) => { // round num and return it - // code here + return Math.round(num); }; const roundUp = (num) => { // round num up and return it - // code here + return Math.ceil(num); }; const addExclamationPoint = (str) => { // add an exclamation point to the end of str and return the new string // 'hello world' -> 'hello world!' - // code here + return `${str}!`; }; const combineNames = (firstName, lastName) => { // return firstName and lastName combined as one string and separated by a space. // 'Lambda', 'School' -> 'Lambda School' // code here + return `${firstName} ${lastName}`; }; const getGreeting = (name) => { // Take the name string and concatenate other strings onto it so it takes the following form: // 'Sam' -> 'Hello Sam!' - // code here + return `Hello ${name}!`; }; // If you can't remember these area formulas then head over to Google or look at the test code. const getRectangleArea = (length, width) => { // return the area of the rectangle by using length and width - // code here + return length * width; }; const getTriangleArea = (base, height) => { // return the area of the triangle by using base and height - // code here + return (height * base) / 2; }; const getCircleArea = (radius) => { // return the rounded area of the circle given the radius - // code here + return Math.round(Math.PI * radius * radius); }; const getRectangularPrismVolume = (length, width, height) => { // return the volume of the 3D rectangular prism given the length, width, and height - // code here + return length * width * height; }; // Do not modify code below this line. From 75d3f26f506b1668bc7b6f90c18580bb0bad9f6e Mon Sep 17 00:00:00 2001 From: ubuntu Date: Sat, 17 Feb 2018 14:44:46 -0600 Subject: [PATCH 04/14] More progress... --- src/project-2.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/project-2.js b/src/project-2.js index 5fe0047..ec0ee3d 100644 --- a/src/project-2.js +++ b/src/project-2.js @@ -3,6 +3,9 @@ const getBiggest = (x, y) => { // x and y are integers. Return the larger integer // if they are the same return either one + if (x > y) return x; + if (y > x) return y; + return x; }; const greeting = (language) => { @@ -11,15 +14,21 @@ const greeting = (language) => { // language: 'Spanish' -> 'Hola!' // language: 'Chinese' -> 'Ni Hao!' // if language is undefined return 'Hello!' + if (language === 'German') return 'Guten Tag!'; + if (language === 'Spanish') return 'Hola!'; + if (language === 'Chinese') return 'Ni Hao!'; + return 'Hello!'; }; const isTenOrFive = (num) => { // return true if num is 10 or 5 // otherwise return false + return num === 10 || num === 5; }; const isInRange = (num) => { // return true if num is less than 50 and greater than 20 + return num < 50 && num > 20; }; const isInteger = (num) => { @@ -29,6 +38,8 @@ const isInteger = (num) => { // -10 -> true // otherwise return false // hint: you can solve this using Math.floor + if (num > Math.floor(num)) return false; + return true; }; const fizzBuzz = (num) => { @@ -36,6 +47,10 @@ const fizzBuzz = (num) => { // if num is divisible by 5 return 'buzz' // if num is divisible by 3 & 5 return 'fizzbuzz' // otherwise return num + if (num % 3 === 0 && num % 5 === 0) return 'fizzbuzz'; + if (num % 3 === 0) return 'fizz'; + if (num % 5 === 0) return 'buzz'; + return num; }; const isPrime = (num) => { @@ -48,6 +63,7 @@ const isPrime = (num) => { const returnFirst = (arr) => { // return the first item from the array + return arr[0]; }; const returnLast = (arr) => { From e3cc9a6522611a8c8c5a763bd79bd894dcd54102 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Sat, 17 Feb 2018 14:45:43 -0600 Subject: [PATCH 05/14] Just another commit. --- src/project-2.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/project-2.js b/src/project-2.js index ec0ee3d..0c6c05b 100644 --- a/src/project-2.js +++ b/src/project-2.js @@ -68,10 +68,12 @@ const returnFirst = (arr) => { const returnLast = (arr) => { // return the last item of the array + return arr[arr.length - 1]; }; const getArrayLength = (arr) => { // return the length of the array + return arr.length; }; const incrementByOne = (arr) => { From 890217e8defda7f8aadd2206ab9fe9b9283d9930 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Sat, 17 Feb 2018 14:46:39 -0600 Subject: [PATCH 06/14] Let's keep this rolling! --- src/project-2.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/project-2.js b/src/project-2.js index 0c6c05b..7b5522c 100644 --- a/src/project-2.js +++ b/src/project-2.js @@ -80,6 +80,10 @@ const incrementByOne = (arr) => { // arr is an array of integers // increase each integer by one // return the array + for (let i = 0; i < arr.length; i++) { + arr[i] += 1; + } + return arr; }; const addItemToArray = (arr, item) => { From 008dc532a6a691863be44a1ed31a6e15cd20b431 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Sat, 17 Feb 2018 14:50:53 -0600 Subject: [PATCH 07/14] Getting my grind while on the bus to work! --- src/project-2.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/project-2.js b/src/project-2.js index 7b5522c..7d0a127 100644 --- a/src/project-2.js +++ b/src/project-2.js @@ -89,12 +89,16 @@ const incrementByOne = (arr) => { const addItemToArray = (arr, item) => { // add the item to the end of the array // return the array + arr.push(item); + return arr; }; const addItemToFront = (arr, item) => { // add the item to the front of the array // return the array // hint: use the array method .unshift + arr.unshift(item); + return arr; }; const wordsToSentence = (words) => { @@ -102,6 +106,7 @@ const wordsToSentence = (words) => { // return a string that is all of the words concatenated together // spaces need to be between each word // example: ['Hello', 'world!'] -> 'Hello world!' + return words.join(' '); }; const contains = (arr, item) => { @@ -112,6 +117,11 @@ const contains = (arr, item) => { const addNumbers = (numbers) => { // numbers is an array of integers. // add all of the integers and return the value + let total = 0; + for (let i = 0; i < numbers.length; i++) { + total += numbers[i]; + } + return total; }; const averageTestScore = (testScores) => { From adc41092b89e700aa859069f74216da23f1ef68f Mon Sep 17 00:00:00 2001 From: ubuntu Date: Sat, 17 Feb 2018 14:53:59 -0600 Subject: [PATCH 08/14] Keep going... --- src/project-2.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/project-2.js b/src/project-2.js index 7d0a127..24dfd42 100644 --- a/src/project-2.js +++ b/src/project-2.js @@ -112,6 +112,10 @@ const wordsToSentence = (words) => { const contains = (arr, item) => { // check to see if item is inside of arr // return true if it is, otherwise return false + for (let i = 0; i < arr.length; i++) { + if (arr[i] === item) return true; + } + return false; }; const addNumbers = (numbers) => { From 38c4cf9b14c8b5310978bae5335eab882696e3dc Mon Sep 17 00:00:00 2001 From: ubuntu Date: Sat, 17 Feb 2018 14:58:33 -0600 Subject: [PATCH 09/14] Will come back and do prime function. --- src/project-2.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/project-2.js b/src/project-2.js index 24dfd42..fcc6de4 100644 --- a/src/project-2.js +++ b/src/project-2.js @@ -131,11 +131,23 @@ const addNumbers = (numbers) => { const averageTestScore = (testScores) => { // testScores is an array. Iterate over testScores and compute the average. // return the average + let rawTotal = 0; + for (let i = 0; i < testScores.length; i++) { + rawTotal += testScores[i]; + } + return rawTotal / testScores.length; }; const largestNumber = (numbers) => { // numbers is an array of integers // return the largest integer + let largest = 0; + for (let i = 0; i < numbers.length; i++) { + if (numbers[i] > largest) { + largest = numbers[i]; + } + } + return largest; }; // Do not modify code below this line. From 4ce25a837e84e4f96ce4017d771498d8d4d991f8 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Sat, 17 Feb 2018 15:42:01 -0600 Subject: [PATCH 10/14] Still working on it before I have to clock in for work... --- src/project-3.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/project-3.js b/src/project-3.js index 7ca1430..f6806c3 100644 --- a/src/project-3.js +++ b/src/project-3.js @@ -5,6 +5,11 @@ const makeCat = (name, age) => { // add an age property to the object with the value set to the age argument // add a method called meow that returns the string 'Meow!' // return the object + const cat = {}; + cat.name = name; + cat.age = age; + cat.meow = () => 'Meow!'; + return cat; }; const addProperty = (object, property) => { From 87b08b83c06c9a68ec86c64b4cdcbbcb9868b6d6 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Sat, 17 Feb 2018 15:50:06 -0600 Subject: [PATCH 11/14] This object can take its method and shove it up its void! --- src/project-3.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/project-3.js b/src/project-3.js index f6806c3..50b875f 100644 --- a/src/project-3.js +++ b/src/project-3.js @@ -16,17 +16,21 @@ const addProperty = (object, property) => { // add the property to the object with a value of null // return the object // note: the property name is NOT 'property'. The name is the value of the argument called property (a string) + object[property] = null; + return object; }; const invokeMethod = (object, method) => { // method is a string that contains the name of a method on the object // invoke this method // nothing needs to be returned + object[method](); }; const multiplyMysteryNumberByFive = (mysteryNumberObject) => { // mysteryNumberObject has a property called mysteryNumber // multiply the mysteryNumber property by 5 and return the product + }; const deleteProperty = (object, property) => { From b0935ae99dace7682df92279ad545b56d9caeb4f Mon Sep 17 00:00:00 2001 From: ubuntu Date: Sun, 18 Feb 2018 15:48:38 -0600 Subject: [PATCH 12/14] Got some more of project-3.js working! --- src/project-3.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/project-3.js b/src/project-3.js index 50b875f..afd2c80 100644 --- a/src/project-3.js +++ b/src/project-3.js @@ -30,34 +30,51 @@ const invokeMethod = (object, method) => { const multiplyMysteryNumberByFive = (mysteryNumberObject) => { // mysteryNumberObject has a property called mysteryNumber // multiply the mysteryNumber property by 5 and return the product - + return mysteryNumberObject.mysteryNumber * 5; }; const deleteProperty = (object, property) => { // remove the property from the object // return the object + delete object[property]; + return object; }; const newUser = (name, email, password) => { // create a new object with properties matching the arguments passed in. // return the new object + const user = {}; + user.name = name; + user.email = email; + user.password = password; + return user; }; const hasEmail = (user) => { // return true if the user has a value for the property 'email' // otherwise return false + if (!user.email) return false; + return true; }; const hasProperty = (object, property) => { // return true if the object has the value of the property argument // property is a string // otherwise return false + const entries = Object.entries(object); + for (let i = 0; i < entries.length; i++) { + if (entries[i][0] === property) { + return true; + } + } + return false; }; const verifyPassword = (user, password) => { // check to see if the provided password matches the password property on the user object // return true if they match // otherwise return false + return user.password === password; }; const updatePassword = (user, newPassword) => { From eded9ebd4339241dc6b2d56272ee40e4e34ef444 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Sun, 18 Feb 2018 16:05:58 -0600 Subject: [PATCH 13/14] Guess who just finished all of project-3.js??upower -d --- src/project-3.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/project-3.js b/src/project-3.js index afd2c80..1ca48f1 100644 --- a/src/project-3.js +++ b/src/project-3.js @@ -80,12 +80,16 @@ const verifyPassword = (user, password) => { const updatePassword = (user, newPassword) => { // replace the existing password on the user object with the value of newPassword // return the object + user.password = newPassword; + return user; }; const addFriend = (user, newFriend) => { // user has a property called friends that is an array // add newFriend to the end of the friends array // return the user object + user.friends.push(newFriend); + return user; }; const setUsersToPremium = (users) => { @@ -93,6 +97,10 @@ const setUsersToPremium = (users) => { // each user object has the property 'isPremium' // set each user's isPremium property to true // return the users array + for (let i = 0; i < users.length; i++) { + users[i].isPremium = true; + } + return users; }; const sumUserPostLikes = (user) => { @@ -101,6 +109,11 @@ const sumUserPostLikes = (user) => { // each post object has an integer property called 'likes' // sum together the likes from all the post objects // return the sum + let sum = 0; + for (let i = 0; i < user.posts.length; i++) { + sum += user.posts[i].likes; + } + return sum; }; const addCalculateDiscountPriceMethod = (storeItem) => { @@ -113,6 +126,11 @@ const addCalculateDiscountPriceMethod = (storeItem) => { // discountPrice = 20 - (20 * .2) // Make sure you return storeItem after adding the method to it // hint: arrow functions don't bind a this + storeItem.calculateDiscountPrice = function () { + const discount = this.price * this.discountPercentage; + return this.price - discount; + }; + return storeItem; }; // Do not modify code below this line. From 3636d8b9a15636de8fc3c23fd7d88c219d667aab Mon Sep 17 00:00:00 2001 From: ubuntu Date: Mon, 19 Feb 2018 01:44:25 -0600 Subject: [PATCH 14/14] Fun challenge! --- src/project-4.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/project-4.js b/src/project-4.js index 3a3a186..c8cbf8b 100644 --- a/src/project-4.js +++ b/src/project-4.js @@ -1,31 +1,46 @@ const getFirstItem = (collection, cb) => { // invoke the callback function and pass the first item from the collection in as an argument + cb(collection[0]); }; const getLength = (collection, cb) => { // Write a function called getLength that passes the length of the array into the callback + cb(collection.length); }; const getLastItem = (collection, cb) => { // Write a function called getLastItem which passes the getLastItem item of the array into the callback + cb(collection[collection.length - 1]); }; const sumNums = (x, y, cb) => { // Write a function called sumNums that adds two numbers and passes the result to the callback + cb(x + y); }; const multiplyNums = (x, y, cb) => { // Write a function called multiplyNums that multiplies two numbers and passes the result to the callback + cb(x * y); }; const contains = (collection, item, cb) => { // Write a function called contains that checks if an item is present inside of the given array. // Pass true to the callback if it is, otherwise pass false + let isPresent = false; + for (let i = 0; i < collection.length; i++) { + if (collection[i] === item) { + isPresent = true; + } + } + cb(isPresent); }; const removeDuplicates = (collection, cb) => { // Write a function called removeDuplicates that removes all duplicate values from the given array. // Pass the array to the callback function. Do not mutate the original array. + let singles = new Set(collection); + singles = [...singles]; + cb(singles); }; module.exports = {