diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..36f4cb7 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,29 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + +{ + "type": "node", + "request": "launch", + "name": "Node", + "port": 9229, + "protocol": "inspector", + "runtimeExecutable": "npm", + "runtimeArgs": [ + "nodemon", + "start" + ], + "console": "integratedTerminal" +} + // { + // "type": "chrome", + // "request": "launch", + // "name": "Launch Chrome against localhost", + // "url": "http://localhost:8080", + // "webRoot": "${workspaceFolder}" + // } + ] +} \ No newline at end of file diff --git a/BrokenProblems/1 brokenSwapCase.js b/BrokenProblems/1 brokenSwapCase.js new file mode 100644 index 0000000..5090ebe --- /dev/null +++ b/BrokenProblems/1 brokenSwapCase.js @@ -0,0 +1,23 @@ +// Swap Case +// Below is a function that takes in a string and reverses the case of every character and returns the new string. +// It is currently in a broken state and does not run properly. +// It is possible to fix the code by only modifying the existing code, not adding new lines. + +//test data +//'This Is An Example' becomes 'tHIS iS aN eXAMPLE' +//'boB rOss IS thE OrIgInAl GanGster' Becomes 'BOb RoSS is THe oRiGiNaL gANgSTER' + + +function caseReverse(str) { + var strArray = str.split(' '); + for (var i = 1; i < strArray.length; i++) { + if (strArray[i] === strArray[i].toUpperCase()) { + strArray[i].toLowerCase(); + } else { + strArray[i].toUpperCase(); + } + } + return strArray +} + +console.log(caseReverse('boB rOss IS thE OrIgInAl GanGster')); \ No newline at end of file diff --git a/BrokenProblems/arrayByReference.js b/BrokenProblems/arrayByReference.js new file mode 100644 index 0000000..6ea1269 --- /dev/null +++ b/BrokenProblems/arrayByReference.js @@ -0,0 +1,54 @@ +// Below is some broken code. Read over all the code below, at the end you will +// see that the results are not what you would expect. Look over the code and +// try and identify where the issue is caused. You will want to console log +// oldInventory and newInventory often to see how it changes. + +let oldInventory = [ + ['calico', 'tabby'], + ['lab', 'corgi', 'rottweiler'], + ['goldfish', 'beta', 'angel fish', 'flounder'] +] + +// Write a function to count the number of animals in the pet shop's old inventory + +function countInventory(arr) { + let count = 0; + + arr.forEach(group => count += group.length) + + return count +} +console.log('countInventory:', countInventory(oldInventory)) + +// All of the animals were very popular and were all sold in the past week +// these same animals were ordered for the next week +let newInventory = oldInventory + +// some new, exotic animals were ordered for the next week as well. +newInventory.push(['gorilla', 'alligator', 'lion', 'humpback whale']) +console.log(newInventory, oldInventory); + +// the pet store needs to know how many more pens they need for the new animals +// write a new function to count the number of animals in both the old and new inventory. +// this function should return the difference in number of animals between the old and new inventories (new - old) + +function compareInventory(oldArr, newArr) { + let oldCount = 0, newCount = 0; + + oldArr.forEach(group => oldCount += group.length) + newArr.forEach(group => newCount += group.length) + + return newCount - oldCount +} +console.log('compareInventory:', compareInventory(oldInventory, newInventory)) + + + + + + + + + + + diff --git a/BrokenProblems/brokenBusTracker.js b/BrokenProblems/brokenBusTracker.js index b63a027..4399c8c 100644 --- a/BrokenProblems/brokenBusTracker.js +++ b/BrokenProblems/brokenBusTracker.js @@ -1,19 +1,19 @@ // Number of people in the bus // -// There is a bus moving in the city, and it takes and drop some people in each bus stop. +// There is a bus moving in the city, and it picks up and drops off some people at each bus stop. // -// You are provided a list (or array in JS) of integer array. Each integer array has two items which represent number of people get into bus (The first item) and number of people get off the bus (The second item). +// You are provided an array of integer arrays. Each integer array has two items which represent number of people that the bus picks up (The first item) and number of people that the bus drops off (The second item). // -// The first integer array has 0 number in the second item, since the bus is empty in the first bus stop. +// The first integer array has the number 0 in the second item, since the bus is empty in the first bus stop. // -// Your task is to return number of people who are still in the bus after the last bus station. Even though it is the last stop, some people don't get off the bus, and they are probably sleeping there :D +// Your task is to return the number of people who are still in the bus after the last bus station. Even though it is the last stop, some people don't get off the bus, and they are probably sleeping there :D // -// Take a look on the test cases. +// Take a look at the test cases. // // Please keep in mind that the test cases ensure that the number of people in the bus is always >= 0. So the return integer can't be negative. // number([[10,0],[3,5],[5,8]]) should return 5 -// number([[3,0],[9,1],[4,10],[12,2],[6,1],[7,10]]) should retrun 17 +// number([[3,0],[9,1],[4,10],[12,2],[6,1],[7,10]]) should return 17 // number([[3,0],[9,1],[4,8],[12,2],[6,1],[7,8]]) Should return 21 let stops = [[3, 0], [9, 1], [4, 8], [12, 2], [6, 1], [7, 8]] diff --git a/BrokenProblems/brokenFactorial.js b/BrokenProblems/brokenFactorial.js index 8ce5782..a4cfc1d 100644 --- a/BrokenProblems/brokenFactorial.js +++ b/BrokenProblems/brokenFactorial.js @@ -6,27 +6,14 @@ // 5 factorial is written as 5! // 5! = 1x2x3x4x5 = 120 - -function factorial(num) { - let total = 1; - for(let i = 0; i < num; i += 1) { - total = i * total; - } - return total; -} - console.log(factorial(5)); - - -// fixed version -function factorialFixed(num) { - let total = 1; - for (let i = 1; i <= num; i += 1) { - total *= i; +var factorial = function (num) { + let toatl = 0; + for (let i = 0; i < number; i += 1) { + return total += i; } - return total; + } -console.log(factorialFixed(5)); -console.log(factorialFixed(6)); + diff --git a/BrokenProblems/brokenLargestEven.js b/BrokenProblems/brokenLargestEven.js index d70c90b..1aeb3de 100644 --- a/BrokenProblems/brokenLargestEven.js +++ b/BrokenProblems/brokenLargestEven.js @@ -1,10 +1,10 @@ // Find the largest Even number -let listOfNums = [2, 5, 8, 23, 765, 2341, 757, 143326, 5786, 678, 35, 27, 235, 765]; +let listOfNums = [2, 5, 8, 23, 765, 2341, 757, 143326, 5786, 678, 35, 27, 235, 765, 14332654]; function largestEven(nums) { - for (var i = 0; i < nums.length; i++) { + for (var i = 0; i < nums.length - 1; i++) { var largestEven = 0; if (nums[i] % 2 === 1 && nums[i] < largestEven) { largestEven = nums[i]; diff --git a/BrokenProblems/brokenSwapCase.js b/BrokenProblems/brokenSwapCase.js deleted file mode 100644 index f75a31e..0000000 --- a/BrokenProblems/brokenSwapCase.js +++ /dev/null @@ -1,21 +0,0 @@ -//Swap Case -//create a function that takes in a string and revereses the case of every character and returns the new string. - -//test data -//'This Is An Example' becomes 'tHIS iS aN eXAMPLE' -//'PoOh bEAr IS thE OrIgInAl GanGster' Becomes 'pOoH BeaR is THe oRiGiNaL gANgSTER' - - -function caseReverse(str) { - var strArray = str.split(' '); - for (var i = 1; i < strArray.length; i++) { - if (strArray[i] === strArray[i].toUpperCase()) { - strArray[i].toLowerCase(); - } else { - strArray[i].toUpperCase(); - } - } - return strArray -} - -console.log(caseReverse('PoOh bEAr IS thE OrIgInAl GanGster')); \ No newline at end of file diff --git a/BrokenProblems/vowelCounter.js b/BrokenProblems/vowelCounter.js index 3b11575..13dff2d 100644 --- a/BrokenProblems/vowelCounter.js +++ b/BrokenProblems/vowelCounter.js @@ -2,32 +2,44 @@ // We will consider that a, e, i, o and u are vowels for the sake of this problem. -var vowelString = "How many vowels are in this sentence?"; // -> 11 +var vowelString = "Bob Ross can see the 4th dimension"; // -> 10 function vowelCounter(str) { str.split('') let total = 0; - str.forEach(item => { + str.forEach(item, i => { switch (item) { case 'A': - total++; + total += total++ break; case 'E': - total++; + total += total++ break; case 'I': - total++; + total += total++ break; case 'o': - total++; + total += total++ break; case 'U' - total++; + total += total++ break; } return -} + } console.log(vowelCounter(vowelString)); -// This one can be fixed by altering existing lines and adding only one \ No newline at end of file + +// ----------------------------------------------------------------------------------- +// Teaching Notes +// The switch will probably be new to the students. This will be a good chance for them +// to practice looking up on their own how something works. + +// Also this one is missing a lot of brackets/parenthesis. Take the time to show them +// how proper indentation can help make it easier to find missing things. Following the +// indentation lines down can show where miss matching is happening. + +// Finally the ++ is done specifically to show that it doesn't actually increment until +// after the operation. thus the result comes out a 0. Take this time to show them how ++x +// and x++ works differently using console logs. \ No newline at end of file diff --git a/Cart/Part1-Setup-removeFromCart.js b/Cart/Part1-Setup-removeFromCart.js new file mode 100644 index 0000000..cbfe5e1 --- /dev/null +++ b/Cart/Part1-Setup-removeFromCart.js @@ -0,0 +1,25 @@ +// Over a few toy problems we will be building out a class that constructs a cart object and also includes a few methods to manipulate the data, things like adding to the cart and calculating the total. +// To start you will want to make a class called Cart that includes a constructor function. Have the constructor function take in a single parameter that will be the items in the cart. Set that value equal to a value called this.cart +// Second we will want to create a method that will take in an id and then remove the item from the cart with the matching id +// You will want to save this because we will be adding to it in the future. + +[ + { + id: 1, + product: 'Bob Ross Paint Kit', + price: 45.99, + quantity: 2, + }, + { + id: 2, + product: 'Paint Palette', + price: 7.99, + quantity: 3, + }, + { + id: 3, + product: 'Paint Thinner', + price: 15.99, + quantity: 2, + }, +]; diff --git a/Cart/Part1-removeFromCart.js b/Cart/Part1-removeFromCart.js deleted file mode 100644 index 934a001..0000000 --- a/Cart/Part1-removeFromCart.js +++ /dev/null @@ -1,32 +0,0 @@ -// Below is an array of products that are in a cart. -// Write a function That will take in an id of an item to be removed from the cart and the cart array. -// The funciton will remove the item from the array if it exists. -// When you have updated the cart then return the new cart. - - -let cart = [{ - id: 1, - product: "Snapple Raspberry Tea", - price: 16.82, - quantity: 2 -}, { - id: 2, - product: "Wine - Peller Estates Late", - price: 15.07, - quantity: 3 -}, { - id: 3, - product: "Isomalt", - price: 6.42, - quantity: 2 -}, { - id: 4, - product: "Green Scrubbie Pad H.duty", - price: 15.33, - quantity: 3 -}, { - id: 5, - product: "Soup Campbells Split Pea And Ham", - price: 4.03, - quantity: 3 -}] \ No newline at end of file diff --git a/Cart/Part1-removeFromCartFinished.js b/Cart/Part1-removeFromCartFinished.js deleted file mode 100644 index 72c7cbf..0000000 --- a/Cart/Part1-removeFromCartFinished.js +++ /dev/null @@ -1,44 +0,0 @@ -// Below is an array of products that are in a cart. -// Write a function That will take in an id of an item to be removed from the cart and the cart array. -// The funciton will remove the item from the array if it exists. -// When you have updated the cart then return the new cart. - - -let cart = [{ - id: 1, - product: "Snapple Raspberry Tea", - price: 16.82, - quantity: 2 - }, { - id: 2, - product: "Wine - Peller Estates Late", - price: 15.07, - quantity: 3 - }, { - id: 3, - product: "Isomalt", - price: 6.42, - quantity: 2 - }, { - id: 4, - product: "Green Scrubbie Pad H.duty", - price: 15.33, - quantity: 3 - }, { - id: 5, - product: "Soup Campbells Split Pea And Ham", - price: 4.03, - quantity: 3 - }] - - function removeFromCart(id, currentCart) { - let newCart = currentCart; - for (let i = 0; i < newCart.length; i++) { - if(newCart[i].id === id) { - newCart.splice(i,1) - } - } - return newCart; - } - - cart = removeFromCart(2, cart) diff --git a/Cart/Part2-calculateTotal.js b/Cart/Part2-calculateTotal.js index 8dc8344..a5bbe09 100644 --- a/Cart/Part2-calculateTotal.js +++ b/Cart/Part2-calculateTotal.js @@ -1,30 +1,6 @@ -// Below is an array of products that are in a cart. -// Write a function that will take in the cart and a tax amount and calculate the total price of the cart with the tax. -// Return the total of the cart rounded the 2nd decimal place - -let cart = [{ - id: 1, - product: 'Snapple Raspberry Tea', - price: 16.82, - quantity: 2 -}, { - id: 2, - product: 'Wine - Peller Estates Late', - price: 15.07, - quantity: 3 -}, { - id: 3, - product: 'Isomalt', - price: 6.42, - quantity: 2 -}, { - id: 4, - product: 'Green Scrubbie Pad H.duty', - price: 15.33, - quantity: 3 -}, { - id: 5, - product: 'Soup Campbells Split Pea And Ham', - price: 4.03, - quantity: 3 -}]; \ No newline at end of file +// We will be building onto the same Cart class from earlier. +// This time we are adding the functions to calculate the total price of the cart. +// First we will be doing the calculate total method. Before we can do that we need to alter our constructor function to take in a tax rate, and keep track of the total price of the cart. +// Add two values in the constructor called total and taxRate. The constructor function should also take in another parameter and set that to the tax rate. +// When the calculate total runs it should set the total value to the total cost of the cart. +// We will also want this function to run any time we remove an item from the cart so the total automatically updates. We also want this to run after all the initial values are set. \ No newline at end of file diff --git a/Cart/Part2-calculateTotalFinished.js b/Cart/Part2-calculateTotalFinished.js deleted file mode 100644 index c492bfb..0000000 --- a/Cart/Part2-calculateTotalFinished.js +++ /dev/null @@ -1,42 +0,0 @@ -// Below is an array of products that are in a cart. -// Write a function that will take in the cart and a tax amount and calculate the total price of the cart with the tax. -// Return the total of the cart rounded the 2nd decimal place - -let cart = [{ - id: 1, - product: 'Snapple Raspberry Tea', - price: 16.82, - quantity: 2 -}, { - id: 2, - product: 'Wine - Peller Estates Late', - price: 15.07, - quantity: 3 -}, { - id: 3, - product: 'Isomalt', - price: 6.42, - quantity: 2 -}, { - id: 4, - product: 'Green Scrubbie Pad H.duty', - price: 15.33, - quantity: 3 -}, { - id: 5, - product: 'Soup Campbells Split Pea And Ham', - price: 4.03, - quantity: 3 -}]; - - -function calculateTotal(cart, tax) { - let total = 0; - for (let i = 0; i < cart.length; i++) { - total = total + (cart[i].quantity * cart[i].price) - } - return (total * tax).toFixed(2) -} - -let total = calculateTotal(cart, 1.06) -total \ No newline at end of file diff --git a/Cart/Part3-updateQuantity.js b/Cart/Part3-updateQuantity.js index f5c71b9..554cae8 100644 --- a/Cart/Part3-updateQuantity.js +++ b/Cart/Part3-updateQuantity.js @@ -1,31 +1,4 @@ -// Below is an array of products that are in a cart. -// Write a function That will take in an item to modify in the cart and the cart array. -// The funciton will update the quantity of the item you are passing in. -// When you have updated the cart then return the new cart. - -let cart = [{ - id: 1, - product: 'Snapple Raspberry Tea', - price: 16.82, - quantity: 2 -}, { - id: 2, - product: 'Wine - Peller Estates Late', - price: 15.07, - quantity: 3 -}, { - id: 3, - product: 'Isomalt', - price: 6.42, - quantity: 2 -}, { - id: 4, - product: 'Green Scrubbie Pad H.duty', - price: 15.33, - quantity: 3 -}, { - id: 5, - product: 'Soup Campbells Split Pea And Ham', - price: 4.03, - quantity: 3 -}]; \ No newline at end of file +// We will be building onto the same Cart class from earlier. +// This time we are adding in the ability to update the quantity of a specific item in the cart. +// This method will take in two parameters, first being the id of the item to update, and second the quantity to set it to. +// After updating the quantity it should recalculate the total of the whole cart. diff --git a/Cart/Part3-updateQuantityFinished.js b/Cart/Part3-updateQuantityFinished.js deleted file mode 100644 index b576897..0000000 --- a/Cart/Part3-updateQuantityFinished.js +++ /dev/null @@ -1,43 +0,0 @@ -// Below is an array of products that are in a cart. -// Write a function That will take in an item to modify in the cart and the cart array. -// The funciton will update the quantity of the item you are passing in. -// When you have updated the cart then return the new cart. - -let cart = [{ - id: 1, - product: 'Snapple Raspberry Tea', - price: 16.82, - quantity: 2 -}, { - id: 2, - product: 'Wine - Peller Estates Late', - price: 15.07, - quantity: 3 -}, { - id: 3, - product: 'Isomalt', - price: 6.42, - quantity: 2 -}, { - id: 4, - product: 'Green Scrubbie Pad H.duty', - price: 15.33, - quantity: 3 -}, { - id: 5, - product: 'Soup Campbells Split Pea And Ham', - price: 4.03, - quantity: 3 -}]; - -function updateQuantity(product, currentCart) { - let newCart = currentCart - for (let i = 0; i < newCart.length; i++) { - if(newCart[i].id === product.id) { - newCart[i].quantity = product.quantity - } - } - return newCart -} - -cart = updateQuantity({id: 4, quantity: 6}, cart); diff --git a/Cart/Part4-addToCart.js b/Cart/Part4-addToCart.js index e957766..ca286bb 100644 --- a/Cart/Part4-addToCart.js +++ b/Cart/Part4-addToCart.js @@ -1,31 +1,6 @@ -// Below is an array of products that are in a cart. -// Write a function That will take in an item to be added to the cart and the cart array. -// The funciton will add the item to the cart unless it is a duplicate, then update the quantity instead. -// When you have updated the cart then return the new cart. - -let cart = [{ - id: 1, - product: 'Snapple Raspberry Tea', - price: 16.82, - quantity: 2 -}, { - id: 2, - product: 'Wine - Peller Estates Late', - price: 15.07, - quantity: 3 -}, { - id: 3, - product: 'Isomalt', - price: 6.42, - quantity: 2 -}, { - id: 4, - product: 'Green Scrubbie Pad H.duty', - price: 15.33, - quantity: 3 -}, { - id: 5, - product: 'Soup Campbells Split Pea And Ham', - price: 4.03, - quantity: 3 -}]; +// We will be building onto the same Cart class from earlier. +// The final step will be building out the functionality to add items to a cart. +// This method will take in an object that will be the item to add to the cart. +// Before we can just add the item to the cart we need to check if that item already exists. +// If it does exist just increase the quantity by one, if it does not push it into the cart. +// Recalculate the total. \ No newline at end of file diff --git a/Cart/Part4-addToCartFinished.js b/Cart/Part4-addToCartFinished.js deleted file mode 100644 index d25e786..0000000 --- a/Cart/Part4-addToCartFinished.js +++ /dev/null @@ -1,66 +0,0 @@ -// Below is an array of products that are in a cart. -// Write a function That will take in an item to be added to the cart and the cart array. -// The funciton will add the item to the cart unless it is a duplicate, then update the quantity instead. -// When you have updated the cart then return the new cart. - - -let cart = [{ - id: 1, - product: 'Snapple Raspberry Tea', - price: 16.82, - quantity: 2 -}, { - id: 2, - product: 'Wine - Peller Estates Late', - price: 15.07, - quantity: 3 -}, { - id: 3, - product: 'Isomalt', - price: 6.42, - quantity: 2 -}, { - id: 4, - product: 'Green Scrubbie Pad H.duty', - price: 15.33, - quantity: 3 -}, { - id: 5, - product: 'Soup Campbells Split Pea And Ham', - price: 4.03, - quantity: 3 -}]; - -function addToCart(product, cartItems) { - const newCart = cartItems; - let foundDuplicate = false; - for (let i = 0; i < newCart.length; i++) { - if (product.id === newCart[i].id) { - foundDuplicate = true; - newCart[i].quantity += product.quantity; - } - } - if (!foundDuplicate) { - newCart.push(product); - } - - return newCart; -} - -cart = addToCart({ - id: 6, - product: 'Bob Ross Paint', - price: 26.92, - quantity: 2 -}, cart); - -// console.log(cart) - -cart = addToCart({ - id: 1, - product: 'Snapple Raspberry Tea', - price: 16.82, - quantity: 2 -}, cart); - -console.log('duplicate', cart); diff --git a/Cart/overview.md b/Cart/overview.md new file mode 100644 index 0000000..e957c13 --- /dev/null +++ b/Cart/overview.md @@ -0,0 +1,5 @@ +# Cart + +We will be using a class to build out a cart object with methods that will modify the cart object. This should take them a few days to get through maybe 2 or 3 but at the end it should be one class with multiple methods that manipulate the cart data. + +On the first day have them set up the class and using the constructor to have a place to put the cart array. We will be revisiting the constructor in later steps. \ No newline at end of file diff --git a/DailyScheudule.md b/DailyScheudule.md new file mode 100644 index 0000000..7490114 --- /dev/null +++ b/DailyScheudule.md @@ -0,0 +1,4 @@ +# Week 1 + +## Day 1 + diff --git a/Intro/Palindrome.js b/Intro/Palindrome.js deleted file mode 100644 index ec94903..0000000 --- a/Intro/Palindrome.js +++ /dev/null @@ -1,8 +0,0 @@ -//Pallindrome -//write a function that takes in one string as a parameter and tests to see if the string is a pallindrome. A Pallindrome is a word or sentance that is both the same forward and backwards. Have the function return true if it is a pallindrome and false if it is not. - -//Example -//'racecar' returns true -//'thomas the tank' returns false -//'pirateninja' returns false -//'party trap' returns true diff --git a/Intro/averageFinder.js b/Intro/averageFinder.js deleted file mode 100644 index 998cbe7..0000000 --- a/Intro/averageFinder.js +++ /dev/null @@ -1,11 +0,0 @@ -//Average -//write a function that takes in an array of numbers as a parameter. find the average of the numbers and return that value. - -//test data -//[1,2,3,4,5,6,7,8,9,10] returns 5.5 -//[52, 6, 109, 99, 78, 3, 1, -6] returns 36.5 - -//Advanced -//before returning the average, round up to the nearest whole value -//and or -//only find the average of even numbers diff --git a/Intro/longestString.js b/Intro/longestString.js index f31105b..8af62da 100644 --- a/Intro/longestString.js +++ b/Intro/longestString.js @@ -1,5 +1,5 @@ // Toy Problem to find the longest string in an array of strings -// Advanced find the sring with the most vowels +// Advanced find the string with the most vowels // Advanced Advanced find the string with the most number of unique characters const strings = [ @@ -8,5 +8,6 @@ const strings = [ 'walrus viking', 'aztec horse', 'KGB Donkey', - 'Supream leader Snake' + 'Supream leader Snake', + 'God Ross' ]; diff --git a/Intro/timeConvert.js b/Intro/timeConvert.js index 1785f5e..9989fd9 100644 --- a/Intro/timeConvert.js +++ b/Intro/timeConvert.js @@ -1,72 +1,12 @@ -//Time Converter -//write a function that takes in a single num parameter. Assume the number passed in the an amount of time measured in seconds. your function will convert the number of seconds into a string that will depict how many days, hours, minutes and seconds that is. Return one string. +// Time Converter +// Write a function that takes in a single num parameter. +// The number passed is an amount of time measured in seconds. +// Convert the number of seconds into a string that will show how how long the time is in days, hours, minutes and seconds. +// Return one string. -//assume the largest time value will not go bigger than weeks, don't calculate for months +//assume the largest time value will not go bigger than weeks, don't calculate for months. -//Example -// 234 is passed into the function. the function returns "2:54" (minutes: seconds) -// 9087 passed in returns "2:31:17" (hours: minutes: seconds) +// example 68 -> 1:08 - -// Step 1: Clarify - Understand the question -//take a number in seconds and convert it to seconds minutes hours - -// Step 2: Create sample data -// 20 - > 20 -// 60 - > 1:00 -//189 - > 3:09 -//9087 - > 2:31:17 - -// Step 4: Signature - -//function timeShower(seconds: number) -> string - - -// Step 5: List code constructs - -//if conditional -//division, modulous -//variables - - -// Step 6: Pseudo Code -// create a funfunfunction -// declare hours, mins, seconds variable -// if there is more than 60 seconds, divide by 60 and store the result as minutes, the moduous of this number is our remianing seconds -// if there is more than 60 minutes, divide by 60 and store the rusult as hours, the moduouls of this is our remaining minutes - -//return - - -// Step 7: Solve - -// 20 - > 20 -// 60 - > 1:00 -//189 - > 3:09 -//9087 - > 2:31:27 - -function timeShower(input) { - let hours = 0, - minutes = 0, - seconds = 0; - // if there is more than 60 seconds, divide by 60 and store the result as minutes, the moduous of this number is our remianing seconds - if(input > 60) { - minutes = Math.floor(input / 60); - minutes - seconds = input % 60; - } else { - return input + '' - } if(minutes > 60) { - hours = Math.floor(minutes / 60); - minutes = minutes % 60; - hours - } else { - minutes + ':' + seconds - return `${minutes}:${seconds}` - } - return `${hours}:${minutes}:${seconds}` -} - -let x = timeShower(121) - -x; \ No newline at end of file +// Challenges +// \ No newline at end of file diff --git a/Intro/toTheMoon.js b/Intro/toTheMoon.js deleted file mode 100644 index 76af942..0000000 --- a/Intro/toTheMoon.js +++ /dev/null @@ -1,20 +0,0 @@ -// Have you heard about the myth that if you fold a paper enough times, you can reach the moon with it? Sure you do, but exactly how many? Maybe it's time to write a program to figure it out. - -// You know that a piece of paper has a thickness of 0.0001m. Given distance in units of meters, calculate how many times you have to fold the paper to make the paper reach this distance. -// (If you're not familiar with the concept of folding a paper: Each fold doubles its total thickness.) - - -//10 500 - -function foldDistance(distance) { - let paper = 0.0001 - let tracker = 0; - while (paper < distance) { - console.log(paper) - paper *= 2; - tracker++ - } - return tracker -} - -console.log(foldDistance(384400000)) diff --git a/Intro/vowelCounter.js b/Intro/vowelCounter.js deleted file mode 100644 index d7bab86..0000000 --- a/Intro/vowelCounter.js +++ /dev/null @@ -1,5 +0,0 @@ -// Write a function that, given a string, returns the number of vowels in that string. - -// We will consider that a, e, i, o and u are vowels for the sake of this problem. - -var vowelString = "How many vowels are in this sentence?"; // -> 11 diff --git a/Medium/bubbleSort.js b/Medium/bubbleSort.js deleted file mode 100644 index 24af46f..0000000 --- a/Medium/bubbleSort.js +++ /dev/null @@ -1,2 +0,0 @@ -// sort an array of numbers using a bubble sort algorithm. -// do not use array.sort method diff --git a/Medium/isAlt.js b/Medium/isAlt.js index 51a5e68..ec1585d 100644 --- a/Medium/isAlt.js +++ b/Medium/isAlt.js @@ -1,43 +1,7 @@ -// https://www.codewars.com/kata/are-we-alternate - -//Create a function isAlt() that accepts a string as an argument and +// IsAlt +//Create a function isAlt() that accepts a string as an argument and //validates whether the vowels (a, e, i, o, u) and consonants are in alternate order. -function isAlt(str) { - //if the string is one character long return true - if(str.length === 1) return true - - //make a new array that is full of true false values based on if it is a vowel or not - // true is a vowel, false is not - // convert the string to lower case to limit the test needed to run - // split the string into an array to loop through it - // map over each item - var test = str.toLowerCase().split('').map(letter => { - return (/^[aeiou]$/i).test(letter); - }) - //now that we have an array we need to test if they arlternate - //figure out what the first value is in the new array, if false we will start at 0, and 1 for true - if(test[1]) { - var counter = 1; - } else { - var counter = 0; - } - //for every item in the array, loop through it and add 1 to the counter for every true value, - //and minus 1 for every false value - // aslong as the values stays 0 or 1 then we know it alternates perfectly but if it goes higher than that - // we know it has two true's or falses in a row - for(var i = 0; i < test.length; i++) { - if(test[i]) counter++ - else counter-- - //if we stay from perfect alternation, return false - if(counter > 1 || counter < 0) { - return false - } - } - //if everything went smoothly return true - return true -} - isAlt("amazon") // true isAlt("apple") diff --git a/Medium/lowestCommonDenominator.js b/Medium/lowestCommonDenominator.js index 40acf91..426827d 100644 --- a/Medium/lowestCommonDenominator.js +++ b/Medium/lowestCommonDenominator.js @@ -13,58 +13,62 @@ const fractionsTwo = [[3, 7], [8, 12], [7, 45]]; function LCD(fractions) { let largestDenominator = 0; - fractions.forEach((fraction) => { - if(fraction[1] > largestDenominator) { - largestDenominator = fraction[1]; + fractions.forEach(fraction => { + const [numerator, denominator] = fraction; + if (denominator > largestDenominator) { + largestDenominator = denominator; } }); let denominatorsAreDivisibleByCounter = 0; - let currentLcdToCheck = largestDenominator; + let currentLCDToCheck = largestDenominator; const numberOfFractions = fractions.length; do { denominatorsAreDivisibleByCounter = 0; - fractions.forEach((fraction) => { + fractions.forEach(fraction => { const fractionsDenominator = fraction[1]; - if (currentLcdToCheck % fractionsDenominator === 0) { + if (currentLCDToCheck % fractionsDenominator === 0) { denominatorsAreDivisibleByCounter += 1; } }); - if(denominatorsAreDivisibleByCounter !== numberOfFractions) { + if (denominatorsAreDivisibleByCounter !== numberOfFractions) { denominatorsAreDivisibleByCounter = 0; - currentLcdToCheck += largestDenominator; + currentLCDToCheck += largestDenominator; } } while (denominatorsAreDivisibleByCounter !== numberOfFractions); - return fractions.map((fraction) => { - const numberToMultiplyBy = currentLcdToCheck / fraction[1]; + + const commonDenominatorFractions = fractions.map(fraction => { + const numberToMultiplyBy = currentLCDToCheck / fraction[1]; fraction[0] = numberToMultiplyBy * fraction[0]; fraction[1] = numberToMultiplyBy * fraction[1]; return fraction; }); + + return commonDenominatorFractions; } const x = LCD(fractionsOne); x; const y = LCD(fractionsTwo); y; -// function lowestCommonDenominator (fractions) { -// var foundDenominator = false; -// for (var i = 1; foundDenominator === false; i++) { -// var tracker = 0; -// for (var j = 0; j < fractions.length; j++) { -// if(i % fractions[j][1] === 0) { -// tracker++; -// } -// } -// if (tracker === fractions.length) { -// foundDenominator = true; -// for (var k = 0; k < fractions.length; k++) { -// fractions[k][0] = (i / fractions[k][1]) * fractions[k][0]; -// fractions[k][1] = (i / fractions[k][1]) * fractions[k][1]; -// } -// return fractions -// } -// } -// } +function lowestCommonDenominator(fractions) { + let foundDenominator = false; + for (let i = 1; foundDenominator === false; i++) { + let tracker = 0; + for (let j = 0; j < fractions.length; j++) { + if (i % fractions[j][1] === 0) { + tracker++; + } + } + if (tracker === fractions.length) { + foundDenominator = true; + for (let k = 0; k < fractions.length; k++) { + fractions[k][0] = i / fractions[k][1] * fractions[k][0]; + fractions[k][1] = i / fractions[k][1] * fractions[k][1]; + } + return fractions; + } + } +} -// lowestCommonDenominator(fractions); -// lowestCommonDenominator(fractionsTwo) +lowestCommonDenominator(fractions); +lowestCommonDenominator(fractionsTwo); diff --git a/Problems/Palindrome.js b/Problems/Palindrome.js new file mode 100644 index 0000000..e4b8aad --- /dev/null +++ b/Problems/Palindrome.js @@ -0,0 +1,12 @@ +// Palindrome +// Write a function that will return true or false if a given string is a palindrome or not. +// A palindrome is a string that is the same forwards and backwards. + +// Example +// 'taco cat' returns true +// 'thomas the tank' returns false +// 'party trap' returns true + +// Extra Bonus +// Have it the function be case insensitive +// Have it ignore are non alphabetic characters ' " ! ? , diff --git a/Problems/X's and O'x.js b/Problems/X's and O'x.js new file mode 100644 index 0000000..a5ddf68 --- /dev/null +++ b/Problems/X's and O'x.js @@ -0,0 +1,7 @@ +// X's and O's +// Write a function that is passed in a single string. +// The function should check if there is an equal number of 'X' and 'O' characters. +// The function should be case insensitive. +// return true if there are equal Xs and Os or if there are no Xs and Os. +// return false if they are not equal. + diff --git a/Problems/averageFinder.js b/Problems/averageFinder.js new file mode 100644 index 0000000..408048f --- /dev/null +++ b/Problems/averageFinder.js @@ -0,0 +1,16 @@ +// Average +// Write a function that takes in an array of numbers as a parameter. +// You can assume all values in the array are numbers. +// Find the average of the numbers +// return the average. + +// test data +// [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] +// [52, 6, 109, 99, 78, 3, 1, -6] + +// Bonus Challenges +// Use a for of loop +// Use the reduce method. +// Before returning the average, round up to the nearest whole value. +// Only find the average of the even numbers. +// How would you handle if there were strings? some strings numbers some letters? diff --git a/Problems/bobRossFamilyTree.js b/Problems/bobRossFamilyTree.js new file mode 100644 index 0000000..7966616 --- /dev/null +++ b/Problems/bobRossFamilyTree.js @@ -0,0 +1,79 @@ +let person = { + firstName: 'Bob', + lastName: 'Ross', + age: '54', + favoriteThings: ['Happy little Trees', 'Happy Accidents', 'Groves', 'Mountains'], + children: [ + { + firstName: 'Morgan', + lastName: 'Ross', + age: '32', + favoriteThings: ['Hiking', 'singing'], + children: [ + { + firstName: 'Todd', + lastName: 'Ross', + age: '9', + favoriteThings: ['Rain Dancing', 'Drawing'], + birthday: function () { + return this.age++; + }, + greet: function (greeter) { + return `Hello ${greeter}, My name is ${this.firstName} ${this.lastName}. do you like ${this.favoriteThings[0]}?` + } + }, + { + firstName: 'Doug', + lastName: 'Ross', + age: '11', + favoriteThings: ['Puddle Splashing', 'Getting Jiggy'], + birthday: function () { + return this.age++; + }, + greet: function (greeter) { + return `Hello ${greeter}, My name is ${this.firstName} ${this.lastName}. do you like ${this.favoriteThings[0]}?` + } + } + ], + birthday: function () { + return this.age++; + }, + greet: function (greeter) { + return `Hello ${greeter}, My name is ${this.firstName} ${this.lastName}. do you like ${this.favoriteThings[0]}?` + } + }, + { + firstName: 'Steve', + lastName: 'Ross', + age: '35', + favoriteThings: ['Yodeling', 'Kareoke'], + children: [], + birthday: function () { + return this.age++; + }, + greet: function (greeter) { + return `Hello ${greeter}, My name is ${this.firstName} ${this.lastName}. do you like ${this.favoriteThings[0]}?` + } + } + ], + birthday: function () { + return this.age++; + }, + greet: function (greeter) { + return `Hello ${greeter}, My name is ${this.firstName} ${this.lastName}. do you like ${this.favoriteThings[0]}?` + } +} + +// Access 'Happy accidents' from Bob's favorite things. + +// Run Bob Ross' greet method. + +// Access Morgan Ross's age. + +// Access 'Singing' from Morgan's favorite things. + +// Run Morgans Birthday method. + +// Access 'Rain Dancing' from Todd Ross' favorite things. + +// Run Doug Ross' Greet method. \ No newline at end of file diff --git a/Problems/findHighScore.js b/Problems/findHighScore.js new file mode 100644 index 0000000..6e867a3 --- /dev/null +++ b/Problems/findHighScore.js @@ -0,0 +1,12 @@ +// High Score +// Write a function that takes in a single parameter, an array of user objects. +// Given the array of user objects, find the user with the highest score. +// return a string that says, 'congratulations [user], you have the high score' + +// Bonus Challenges +// Use the sort method on the array to find the highest score. +// Use the for of loop. +// Do this in one line. + +let users = [{ name: "mark", score: 27 }, { name: "erica", score: 32 }, { name: "martin", score: 33 }, +{ name: "sage", score: 17 }, { name: "horatio", score: 30 }, { name: "james", score: 29 }] diff --git a/Problems/fizzBuzzOrBobRoss.js b/Problems/fizzBuzzOrBobRoss.js new file mode 100644 index 0000000..dadb240 --- /dev/null +++ b/Problems/fizzBuzzOrBobRoss.js @@ -0,0 +1,9 @@ +// FizzBuzz - Bob Ross edition +// write a function that takes in one number. +// Starting at 1, console log every number up to the number passed in. +// If the number being logged is divisible by 3 log 'Bob' instead. +// If the number is divisible by 5 we will log 'Ross' instead. +// If they are divisible by both 3 and 5 we will log 'Bob Ross' + +// Challenge Mode +// Use a 'while' or 'do while' loop \ No newline at end of file diff --git a/Problems/letterFrequency.js b/Problems/letterFrequency.js new file mode 100644 index 0000000..be07367 --- /dev/null +++ b/Problems/letterFrequency.js @@ -0,0 +1,21 @@ +// Letter Frequency + +// Write a function that will take in a single string. +// The function will tally how many times each letter appears in the string. +// The tally will be kept in an object with the property being the letter and the value being how many were found. +// Return the object with how the count of each letter found. +// Ignore Spaces + +// Bob Ross -> {b: 2, o: 2, r: 1, s: 2} +// taco cat -> {t: 2, a: 2, c: 2, o: 1} + + + +// Bonus Challenge +// Alter the function so it instead takes in two strings. +// We want to see if we rearrange the letters of the first string can we enough letters to make the second string. +// If that is possible return true, if it is not return false. + +//('Bob Ross', 'bos ros') -> true +//('Bob Ross', 'boss ross') -> false +//('Bob Ross', 'tim allen') -> false \ No newline at end of file diff --git a/Problems/objectAssign.js b/Problems/objectAssign.js new file mode 100644 index 0000000..d008479 --- /dev/null +++ b/Problems/objectAssign.js @@ -0,0 +1,17 @@ +// Below we have two parts to a cat. But we want one whole cat. +// We need to combine the properties of both catParts and catLimbs into cat so we get one object with all 7 properties. + +let catLimbs = { legs: 4, tail: .5, head: 1 } +let catSounds = { sound: 'Meow', makeSound: function () { return this.sound } } + +let cat = { name: 'Dr. Mittens', favoriteFood: 'fish flesh' } + +// We can use the for in loop to go through each property of an object. +// We will need to do this twice, once for catLimbs and once for catSounds. +// You will also need to use bracket notation. + + +// There has to be a better way to do that. And there is! +// Try searching for Object.assign and looking at what that does. +// Store the result of the Object.assign to a variable. +// Try console.logging all the objects and pay close attention to the results. You may have two variables with all 7 properties. \ No newline at end of file diff --git a/Problems/reverseWords.js b/Problems/reverseWords.js new file mode 100644 index 0000000..46f58b0 --- /dev/null +++ b/Problems/reverseWords.js @@ -0,0 +1,11 @@ +// Word Reverser + +// Write a function that takes in a string and reverses each word but preserves the order of the words. +// Return the string with each word reversed. + +// Examples +// Richard Simmons -> drahciR snommiS +// Bob Ross -> boB ssoR + +// Bonus Challenges +// Don't use the reverse method diff --git a/Problems/thisAndContext.html b/Problems/thisAndContext.html new file mode 100644 index 0000000..73217fd --- /dev/null +++ b/Problems/thisAndContext.html @@ -0,0 +1,103 @@ + + + +
+ + +