From 0412dd1b4a59eba8e8edd240ecc27d75ebd27f02 Mon Sep 17 00:00:00 2001 From: Todd Rasband Date: Fri, 26 Jan 2018 14:43:29 -0700 Subject: [PATCH 01/10] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b5a379e..785041a 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ The intro and medium folders are just random toy problems that I have collected but are not really part of my new plan specifically. Part of my goal with this is to eliminate "advanced toy problems" and make it so every problem will have a variety of approaches and ways to optimize them. ## Purposed Weekly Schedule + Monday: Teaching topic/normal toy problem Tuesday: Cart (Week 5 SQL Cart Schema) Wednesday: HTML From 900e2ee227123d6f5f6b5508ee13838894b0a8c8 Mon Sep 17 00:00:00 2001 From: Todd Rasband Date: Wed, 28 Feb 2018 11:08:15 -0700 Subject: [PATCH 02/10] added problems --- Cart/Part1-removeFromCartFinished.js | 73 ++++++++++++++------------ Cart/Part2-calculateTotalFinished.js | 9 +++- Cart/Part3-updateQuantityFinished.js | 10 ++-- Intro/averageFinder.js | 11 ---- Intro/longestString.js | 5 +- Intro/timeConvert.js | 78 ++++------------------------ Intro/toTheMoon.js | 20 ------- Intro/vowelCounter.js | 5 -- Problems/X's and O'x.js | 7 +++ Problems/averageFinder.js | 15 ++++++ Problems/findHighScore.js | 12 +++++ Problems/fizzBuzzOrBobRoss.js | 9 ++++ Problems/toTheMoon.js | 11 ++++ README.md | 50 ++++++++++++++---- test.html | 34 ++++++++++++ 15 files changed, 194 insertions(+), 155 deletions(-) delete mode 100644 Intro/averageFinder.js delete mode 100644 Intro/toTheMoon.js delete mode 100644 Intro/vowelCounter.js create mode 100644 Problems/X's and O'x.js create mode 100644 Problems/averageFinder.js create mode 100644 Problems/findHighScore.js create mode 100644 Problems/fizzBuzzOrBobRoss.js create mode 100644 Problems/toTheMoon.js create mode 100644 test.html diff --git a/Cart/Part1-removeFromCartFinished.js b/Cart/Part1-removeFromCartFinished.js index 72c7cbf..7848cb3 100644 --- a/Cart/Part1-removeFromCartFinished.js +++ b/Cart/Part1-removeFromCartFinished.js @@ -1,44 +1,49 @@ // 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. +// The function will remove the item from the array if it exists. // When you have updated the cart then return the new cart. +//Advance use a filter function +//Master Do this in one line + 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 - }] + 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) - } +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; } + return newCart; +} + +let removeItem = (id, currentCart) => currentCart.filter(item => item.id !== id) - cart = removeFromCart(2, cart) +let x = removeItem(2, cart); diff --git a/Cart/Part2-calculateTotalFinished.js b/Cart/Part2-calculateTotalFinished.js index c492bfb..0ce4141 100644 --- a/Cart/Part2-calculateTotalFinished.js +++ b/Cart/Part2-calculateTotalFinished.js @@ -2,6 +2,9 @@ // 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 +// Advanced: use a reduce function +// Master: Do this in one line + let cart = [{ id: 1, product: 'Snapple Raspberry Tea', @@ -39,4 +42,8 @@ function calculateTotal(cart, tax) { } let total = calculateTotal(cart, 1.06) -total \ No newline at end of file +total + +let shortTotal = (cart, tax) => (cart.reduce((total, item) => total + (item.price * item.quantity), 0) * tax).toFixed(2) + +console.log(shortTotal(cart, 1.03)); \ No newline at end of file diff --git a/Cart/Part3-updateQuantityFinished.js b/Cart/Part3-updateQuantityFinished.js index b576897..618b432 100644 --- a/Cart/Part3-updateQuantityFinished.js +++ b/Cart/Part3-updateQuantityFinished.js @@ -1,6 +1,6 @@ // 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. +// The function will update the quantity of the item you are passing in. // When you have updated the cart then return the new cart. let cart = [{ @@ -33,11 +33,15 @@ let cart = [{ function updateQuantity(product, currentCart) { let newCart = currentCart for (let i = 0; i < newCart.length; i++) { - if(newCart[i].id === product.id) { + if (newCart[i].id === product.id) { newCart[i].quantity = product.quantity } } return newCart } -cart = updateQuantity({id: 4, quantity: 6}, cart); +cart = updateQuantity({ id: 4, quantity: 6 }, cart); + +let updateQuantityQuick = (product, currentCart) => { + +} \ No newline at end of file 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/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..0567c1a --- /dev/null +++ b/Problems/averageFinder.js @@ -0,0 +1,15 @@ +// 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] + +// 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 even numbers. diff --git a/Problems/findHighScore.js b/Problems/findHighScore.js new file mode 100644 index 0000000..7e4ceae --- /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' + +// 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/toTheMoon.js b/Problems/toTheMoon.js new file mode 100644 index 0000000..b7ef356 --- /dev/null +++ b/Problems/toTheMoon.js @@ -0,0 +1,11 @@ +// To the Moon + +// If you folded a piece of paper in half enough you could theoretically reach any height, but how many times would you have to fold to reach a desired height? + +// Write a function that takes in a single number as a parameter. +// Return how many times would you need to fold a piece of paper to reach the input distance. +// Assume all distances are done in meters, no conversions needed. + +// A piece of paper has a thickness of 0.0001. +// The distance to the moon is 384400000 + diff --git a/README.md b/README.md index 785041a..516c8a0 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,47 @@ The intro and medium folders are just random toy problems that I have collected but are not really part of my new plan specifically. Part of my goal with this is to eliminate "advanced toy problems" and make it so every problem will have a variety of approaches and ways to optimize them. -## Purposed Weekly Schedule +## Problem Solving -Monday: Teaching topic/normal toy problem -Tuesday: Cart (Week 5 SQL Cart Schema) -Wednesday: HTML -Thursday: Broken Toy problem -Friday: Breakfast +Below are steps that should be used for teaching how to solve toy problems. It is vitally important to use this on every toy problem you do from scratch. This teaches them how to break down a toy problem and identify its parts. This is also the exact same steps that should be followed when doing white board problems, Make sure the students know that! Help them to see the value in being clear with your communication and planning. Some steps seem to be not worth while but if a student is struggling with toy problems you should be able to help them see that their problem has to do with one of the steps. + +Doing these steps will add extra time onto the problem so you may want to give them 10 minutes to work before you jump in. + +// Step 1: Clarify - Understand the question + +// Step 2: What data structures are needed + +// Step 3: Create sample data + +// Step 4: Solve Sample Data + +// Step 5: Function Signature + +// Step 6: List code constructs + +// Step 7: Pseudo Code + +// Step 8: Solve + +## Broken Problems + +Every one of these problems do not work. With each one you can solve it by only modifying existing lines (make sure to communicate this to the students), there is no need to write more lines of code. The purpose of this is to teach the students how to become good trouble shooters and develop debugging skills/mindset. A trouble shooting mindset is more like a way of life than just a coding idea. These troubleshooting steps are universal and apply to any subject. + +I recommend leaving these steps on some kind of 'note' software so it can always be visible and on top of your coding window, and you can write down your thoughts as you go along. This also help students see all the steps instead of trying to keep it in their heads. + +Typically the process starts at the Observation step. You may observe, "my code does not work" and that is a viable and helpful observation. From there you need to ask questions. Questions like, what does this line really do? One of the hardest things to question is your own assumptions, and even harder is realizing you are making assumptions. The goal from here is to get confirmations of your assumptions but performing experiments that will give you hard evidence to either prove or disprove your theories. + +1. Observation + +2. Question + +3. Hypothesis + +4. Experiment + +5. Analysis + +6. Conclusion ## HTML @@ -18,10 +52,6 @@ The HTML has a few sites drawn with boxes around them progressing through how to The idea of this one was to try and spend multiple days spread over a few weeks where they built something that felt more real and usable. Also this would help for when students want to build a cart and now you could have them pull up their toy problems for a starting point. -## Broken Problems - -Everyone of these problems does not work. With each one you can solve it by only modifying existing lines, there is not a need to write more lines of code. This is could be a good starting place for teaching the students how to troubleshoot using the scientific method (more on this per request). - ## Teaching topics This is a list of topics I want to teach and to find a toy problem that focuses on teaching each one specifically. I just felt like our toy problems most of the time end up just being the same things over and over. This ensures variety. diff --git a/test.html b/test.html new file mode 100644 index 0000000..f1e5187 --- /dev/null +++ b/test.html @@ -0,0 +1,34 @@ + + + + + + + + Document + + + + +
+ +
+ +
+ + + + + \ No newline at end of file From 176ddfdca1471f042dc49b32b33743033659b2d6 Mon Sep 17 00:00:00 2001 From: Todd Rasband Date: Thu, 1 Mar 2018 16:39:14 -0700 Subject: [PATCH 03/10] added more problems/fixed types/improved instructions --- BrokenProblems/brokenBusTracker.js | 2 +- BrokenProblems/brokenFactorial.js | 2 +- BrokenProblems/brokenSwapCase.js | 10 ++-- BrokenProblems/vowelCounter.js | 6 +-- Cart/Part4-addToCart.js | 2 +- Intro/Palindrome.js | 8 --- Medium/isAlt.js | 40 +-------------- Problems/Palindrome.js | 12 +++++ Problems/averageFinder.js | 7 +-- Problems/bobRossFamilyTree.js | 79 ++++++++++++++++++++++++++++++ Problems/findHighScore.js | 2 +- Problems/objectAssign.js | 35 +++++++++++++ Problems/reverseWords.js | 11 +++++ Problems/toTheMoon.js | 2 + README.md | 9 +--- 15 files changed, 159 insertions(+), 68 deletions(-) delete mode 100644 Intro/Palindrome.js create mode 100644 Problems/Palindrome.js create mode 100644 Problems/bobRossFamilyTree.js create mode 100644 Problems/objectAssign.js create mode 100644 Problems/reverseWords.js diff --git a/BrokenProblems/brokenBusTracker.js b/BrokenProblems/brokenBusTracker.js index b63a027..d54e7ef 100644 --- a/BrokenProblems/brokenBusTracker.js +++ b/BrokenProblems/brokenBusTracker.js @@ -13,7 +13,7 @@ // 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..3910316 100644 --- a/BrokenProblems/brokenFactorial.js +++ b/BrokenProblems/brokenFactorial.js @@ -9,7 +9,7 @@ function factorial(num) { let total = 1; - for(let i = 0; i < num; i += 1) { + for (let i = 0; i < num; i += 1) { total = i * total; } return total; diff --git a/BrokenProblems/brokenSwapCase.js b/BrokenProblems/brokenSwapCase.js index f75a31e..5090ebe 100644 --- a/BrokenProblems/brokenSwapCase.js +++ b/BrokenProblems/brokenSwapCase.js @@ -1,9 +1,11 @@ -//Swap Case -//create a function that takes in a string and revereses the case of every character and returns the new string. +// 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' -//'PoOh bEAr IS thE OrIgInAl GanGster' Becomes 'pOoH BeaR is THe oRiGiNaL gANgSTER' +//'boB rOss IS thE OrIgInAl GanGster' Becomes 'BOb RoSS is THe oRiGiNaL gANgSTER' function caseReverse(str) { @@ -18,4 +20,4 @@ function caseReverse(str) { return strArray } -console.log(caseReverse('PoOh bEAr IS thE OrIgInAl GanGster')); \ No newline at end of file +console.log(caseReverse('boB rOss IS thE OrIgInAl GanGster')); \ No newline at end of file diff --git a/BrokenProblems/vowelCounter.js b/BrokenProblems/vowelCounter.js index 3b11575..eef3324 100644 --- a/BrokenProblems/vowelCounter.js +++ b/BrokenProblems/vowelCounter.js @@ -26,8 +26,6 @@ function vowelCounter(str) { 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 +console.log(vowelCounter(vowelString)); \ No newline at end of file diff --git a/Cart/Part4-addToCart.js b/Cart/Part4-addToCart.js index e957766..29d95d3 100644 --- a/Cart/Part4-addToCart.js +++ b/Cart/Part4-addToCart.js @@ -1,6 +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. +// The function 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 = [{ 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/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/Problems/Palindrome.js b/Problems/Palindrome.js new file mode 100644 index 0000000..ad4b70f --- /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 work even if some letters are uppercase +// Have it work even if some characters are non alphabetic ' " ! ? , diff --git a/Problems/averageFinder.js b/Problems/averageFinder.js index 0567c1a..408048f 100644 --- a/Problems/averageFinder.js +++ b/Problems/averageFinder.js @@ -5,11 +5,12 @@ // return the average. // test data -// [1,2,3,4,5,6,7,8,9,10] +// [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] // [52, 6, 109, 99, 78, 3, 1, -6] -// Challenges +// 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 even numbers. +// 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 index 7e4ceae..6e867a3 100644 --- a/Problems/findHighScore.js +++ b/Problems/findHighScore.js @@ -3,7 +3,7 @@ // 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' -// Challenges +// Bonus Challenges // Use the sort method on the array to find the highest score. // Use the for of loop. // Do this in one line. diff --git a/Problems/objectAssign.js b/Problems/objectAssign.js new file mode 100644 index 0000000..9937ab6 --- /dev/null +++ b/Problems/objectAssign.js @@ -0,0 +1,35 @@ +// Copying and Merging Objects +// Run each code block listed below and pay carful attention to the results of the console.log's + +// You should observe that the objects are not being copied +// Both variables point to the same object and change the same values. +// This phenomenon is called 'passing by reference.' +// Look up Object.assign, it can be a solution to getting around this issue. It is also great a merging objects. + +// Now lets put your Object.assign skills to the test. +// Using Object.assign create a new object that is the combination of 3 other objects. + +// If you swap out all the objects in the code below with arrays you will see a similar phenomenon. +// Two ways to deal with arrays and reference is to use the spread operator '...' or .slice() method. + +// let objOne = { +// name: 'Bob Ross', +// job: 'Joy Giver' +// } +// let objTwo = objOne; +// objTwo.job = "God Painter"; +// console.log(objOne) + + + +// function objectChanger(item) { +// item.job = "Cardio Guru" +// return +// } +// let obj = { +// name: "Richard Simmons", +// job: "Exercise Genie" +// } +// objectChanger(obj) +// console.log(obj) + 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/toTheMoon.js b/Problems/toTheMoon.js index b7ef356..a587cd0 100644 --- a/Problems/toTheMoon.js +++ b/Problems/toTheMoon.js @@ -9,3 +9,5 @@ // A piece of paper has a thickness of 0.0001. // The distance to the moon is 384400000 + + diff --git a/README.md b/README.md index 516c8a0..c0263e5 100644 --- a/README.md +++ b/README.md @@ -34,9 +34,9 @@ Typically the process starts at the Observation step. You may observe, "my code 1. Observation -2. Question +2. Question your assumptions -3. Hypothesis +3. Form Hypothesis 4. Experiment @@ -59,14 +59,9 @@ This is a list of topics I want to teach and to find a toy problem that focuses This is in no way a compleat or finished list. if there is a () next to the title then it is a brief description of a toy problem that could help teach that topic. We should make it clear before hand what method or words they should search so they can do the toy problem.
  • for loop to modify data (map)
  • -
  • nested objects/large objects (my bob ross family tree https://repl.it/@Rasbandit/Bob-Ross-Family-Tree-Test-Data)
  • working with an array of objects
  • -
  • while loop / do while
  • for in/square brackets (loop through every property)
  • -
  • for of (alternative for loop for arrays)
  • -
  • switch (looking for vowels)
  • if and / or (if male and 18)
  • -
  • higher order functions
  • double for loop
  • ## SQL Schema From 130d29ef67b133814dd5d2138d5ed8bd5527d6fe Mon Sep 17 00:00:00 2001 From: Todd Rasband Date: Thu, 8 Mar 2018 14:37:01 -0700 Subject: [PATCH 04/10] added a few --- ...{brokenSwapCase.js => 1 brokenSwapCase.js} | 0 BrokenProblems/arrayByReference.js | 54 +++++++++ BrokenProblems/vowelCounter.js | 30 +++-- Problems/hoisting.js | 0 Problems/letVarConst.js | 0 Problems/letterFrequency.js | 10 ++ Problems/objectAssign.js | 4 +- Problems/thisAndContext.html | 103 ++++++++++++++++++ README.md | 29 +++++ test.html | 34 ------ 10 files changed, 220 insertions(+), 44 deletions(-) rename BrokenProblems/{brokenSwapCase.js => 1 brokenSwapCase.js} (100%) create mode 100644 BrokenProblems/arrayByReference.js create mode 100644 Problems/hoisting.js create mode 100644 Problems/letVarConst.js create mode 100644 Problems/letterFrequency.js create mode 100644 Problems/thisAndContext.html delete mode 100644 test.html diff --git a/BrokenProblems/brokenSwapCase.js b/BrokenProblems/1 brokenSwapCase.js similarity index 100% rename from BrokenProblems/brokenSwapCase.js rename to BrokenProblems/1 brokenSwapCase.js 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/vowelCounter.js b/BrokenProblems/vowelCounter.js index eef3324..13dff2d 100644 --- a/BrokenProblems/vowelCounter.js +++ b/BrokenProblems/vowelCounter.js @@ -2,30 +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)); \ No newline at end of file +console.log(vowelCounter(vowelString)); + + +// ----------------------------------------------------------------------------------- +// 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/Problems/hoisting.js b/Problems/hoisting.js new file mode 100644 index 0000000..e69de29 diff --git a/Problems/letVarConst.js b/Problems/letVarConst.js new file mode 100644 index 0000000..e69de29 diff --git a/Problems/letterFrequency.js b/Problems/letterFrequency.js new file mode 100644 index 0000000..de31786 --- /dev/null +++ b/Problems/letterFrequency.js @@ -0,0 +1,10 @@ +// 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} \ No newline at end of file diff --git a/Problems/objectAssign.js b/Problems/objectAssign.js index 9937ab6..cc50cf1 100644 --- a/Problems/objectAssign.js +++ b/Problems/objectAssign.js @@ -4,7 +4,8 @@ // You should observe that the objects are not being copied // Both variables point to the same object and change the same values. // This phenomenon is called 'passing by reference.' -// Look up Object.assign, it can be a solution to getting around this issue. It is also great a merging objects. +// Look up Object.assign, it can be a solution to getting around this issue. +// It is also great a merging objects. // Now lets put your Object.assign skills to the test. // Using Object.assign create a new object that is the combination of 3 other objects. @@ -21,7 +22,6 @@ // console.log(objOne) - // function objectChanger(item) { // item.job = "Cardio Guru" // return 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 @@ + + + + + + + Page Title + + + + + +

    Open The Console

    + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index c0263e5..085f363 100644 --- a/README.md +++ b/README.md @@ -67,3 +67,32 @@ This is in no way a compleat or finished list. if there is a () next to the titl ## SQL Schema Later in the I would like to do one or who Schema toy problem. So specifically how to build a table for the data you need. Not how to select from it. We spend enough time on how to get data, but not how to structure data. + +## Purposed Toy Problem + +### Week 1 +
      +
    • Day 1: none
    • +
    • Day 2: 45 Minute Fizz Buzz With 8, step Walk through
    • +
    • Day 3: Broken Problems 1, Swap Case
    • +
    • Day 4: Array's and Reference (in prep for react 1)
    • +
    • Day 5: None
    • +
    + +### Week 2 +
      +
    • Day 1: This and Context
    • +
    • Day 2: Bob Ross Family Tree
    • +
    • Day 3: Vowel Counter
    • +
    • Day 4:
    • +
    • Day 5: None
    • +
    + +### Week 3 +
      +
    • Day 1: None
    • +
    • Day 2:
    • +
    • Day 3:
    • +
    • Day 4:
    • +
    • Day 5: None
    • +
    \ No newline at end of file diff --git a/test.html b/test.html deleted file mode 100644 index f1e5187..0000000 --- a/test.html +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - Document - - - - -
    - -
    - -
    - - - - - \ No newline at end of file From 7619e4b58c09fb402500130493e1d68281b51ef1 Mon Sep 17 00:00:00 2001 From: Todd Rasband Date: Mon, 26 Mar 2018 00:46:35 -0600 Subject: [PATCH 05/10] removed unesicary files and added new ones --- BrokenProblems/brokenFactorial.js | 25 +++-------- Cart/Part1-removeFromCart.js | 32 +++++--------- Cart/Part1-removeFromCartFinished.js | 49 --------------------- Cart/Part2-calculateTotal.js | 1 + Cart/Part2-calculateTotalFinished.js | 49 --------------------- Cart/Part3-updateQuantity.js | 6 ++- Cart/Part3-updateQuantityFinished.js | 47 -------------------- Cart/Part4-addToCartFinished.js | 66 ---------------------------- Cart/overview.md | 5 +++ Problems/objectAssign.js | 42 +++++------------- README.md | 19 +++++--- 11 files changed, 52 insertions(+), 289 deletions(-) delete mode 100644 Cart/Part1-removeFromCartFinished.js delete mode 100644 Cart/Part2-calculateTotalFinished.js delete mode 100644 Cart/Part3-updateQuantityFinished.js delete mode 100644 Cart/Part4-addToCartFinished.js create mode 100644 Cart/overview.md diff --git a/BrokenProblems/brokenFactorial.js b/BrokenProblems/brokenFactorial.js index 3910316..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/Cart/Part1-removeFromCart.js b/Cart/Part1-removeFromCart.js index 934a001..72404f5 100644 --- a/Cart/Part1-removeFromCart.js +++ b/Cart/Part1-removeFromCart.js @@ -1,32 +1,20 @@ -// 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. +// over the next few toy problems we will be building out a class that constructs a cart object that also includes a few methods to manipulate the data. +// 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 -let cart = [{ +[{ id: 1, - product: "Snapple Raspberry Tea", - price: 16.82, + product: 'Bob Ross Paint Kit', + price: 45.99, quantity: 2 }, { id: 2, - product: "Wine - Peller Estates Late", - price: 15.07, + product: 'Paint Palette', + price: 7.99, quantity: 3 }, { id: 3, - product: "Isomalt", - price: 6.42, + product: 'Paint Thinner', + price: 15.99, 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 +}]; \ No newline at end of file diff --git a/Cart/Part1-removeFromCartFinished.js b/Cart/Part1-removeFromCartFinished.js deleted file mode 100644 index 7848cb3..0000000 --- a/Cart/Part1-removeFromCartFinished.js +++ /dev/null @@ -1,49 +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 function will remove the item from the array if it exists. -// When you have updated the cart then return the new cart. - -//Advance use a filter function -//Master Do this in one line - - -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; -} - -let removeItem = (id, currentCart) => currentCart.filter(item => item.id !== id) - -let x = removeItem(2, cart); diff --git a/Cart/Part2-calculateTotal.js b/Cart/Part2-calculateTotal.js index 8dc8344..c6455e4 100644 --- a/Cart/Part2-calculateTotal.js +++ b/Cart/Part2-calculateTotal.js @@ -1,5 +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. +// Have the function assume 7% tax rate if one is not passed in (look up default params). // Return the total of the cart rounded the 2nd decimal place let cart = [{ diff --git a/Cart/Part2-calculateTotalFinished.js b/Cart/Part2-calculateTotalFinished.js deleted file mode 100644 index 0ce4141..0000000 --- a/Cart/Part2-calculateTotalFinished.js +++ /dev/null @@ -1,49 +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 - -// Advanced: use a reduce function -// Master: Do this in one line - -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 - -let shortTotal = (cart, tax) => (cart.reduce((total, item) => total + (item.price * item.quantity), 0) * tax).toFixed(2) - -console.log(shortTotal(cart, 1.03)); \ No newline at end of file diff --git a/Cart/Part3-updateQuantity.js b/Cart/Part3-updateQuantity.js index f5c71b9..984042b 100644 --- a/Cart/Part3-updateQuantity.js +++ b/Cart/Part3-updateQuantity.js @@ -1,6 +1,8 @@ // 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. +// Write a function That will take in two parameters. +// One parameter is an object with the id of the item to update, and the quantity to set it to. +// The second parameter is the cart array to be updated. +// The function will update the quantity of the item you are passing in. // When you have updated the cart then return the new cart. let cart = [{ diff --git a/Cart/Part3-updateQuantityFinished.js b/Cart/Part3-updateQuantityFinished.js deleted file mode 100644 index 618b432..0000000 --- a/Cart/Part3-updateQuantityFinished.js +++ /dev/null @@ -1,47 +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 function 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); - -let updateQuantityQuick = (product, currentCart) => { - -} \ 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/Problems/objectAssign.js b/Problems/objectAssign.js index cc50cf1..d008479 100644 --- a/Problems/objectAssign.js +++ b/Problems/objectAssign.js @@ -1,35 +1,17 @@ -// Copying and Merging Objects -// Run each code block listed below and pay carful attention to the results of the console.log's +// 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. -// You should observe that the objects are not being copied -// Both variables point to the same object and change the same values. -// This phenomenon is called 'passing by reference.' -// Look up Object.assign, it can be a solution to getting around this issue. -// It is also great a merging objects. +let catLimbs = { legs: 4, tail: .5, head: 1 } +let catSounds = { sound: 'Meow', makeSound: function () { return this.sound } } -// Now lets put your Object.assign skills to the test. -// Using Object.assign create a new object that is the combination of 3 other objects. +let cat = { name: 'Dr. Mittens', favoriteFood: 'fish flesh' } -// If you swap out all the objects in the code below with arrays you will see a similar phenomenon. -// Two ways to deal with arrays and reference is to use the spread operator '...' or .slice() method. +// 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. -// let objOne = { -// name: 'Bob Ross', -// job: 'Joy Giver' -// } -// let objTwo = objOne; -// objTwo.job = "God Painter"; -// console.log(objOne) - - -// function objectChanger(item) { -// item.job = "Cardio Guru" -// return -// } -// let obj = { -// name: "Richard Simmons", -// job: "Exercise Genie" -// } -// objectChanger(obj) -// console.log(obj) +// 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/README.md b/README.md index 085f363..29d660b 100644 --- a/README.md +++ b/README.md @@ -73,9 +73,9 @@ Later in the I would like to do one or who Schema toy problem. So specifically h ### Week 1
    • Day 1: none
    • -
    • Day 2: 45 Minute Fizz Buzz With 8, step Walk through
    • -
    • Day 3: Broken Problems 1, Swap Case
    • -
    • Day 4: Array's and Reference (in prep for react 1)
    • +
    • Day 2: 45 Minute Fizz Buzz With '8 step Walk through'
    • +
    • Day 3: Broken - Swap Case
    • +
    • Day 4: Broken - Array's and Reference
    • Day 5: None
    @@ -83,14 +83,23 @@ Later in the I would like to do one or who Schema toy problem. So specifically h
    • Day 1: This and Context
    • Day 2: Bob Ross Family Tree
    • -
    • Day 3: Vowel Counter
    • -
    • Day 4:
    • +
    • Day 3: Broken - Vowel Counter
    • +
    • Day 4: Cart - Remove From Cart
    • Day 5: None
    ### Week 3
    • Day 1: None
    • +
    • Day 2: Cart - Calculate Total
    • +
    • Day 3: Cart - Update Quantity / Add to Cart
    • +
    • Day 4: Broken - Factorial
    • +
    • Day 5: None
    • +
    + +### Week 4 +
      +
    • Day 1: Object.Assign
    • Day 2:
    • Day 3:
    • Day 4:
    • From f02d463e78bf692d83f1650a4aac3db8cf6eddd8 Mon Sep 17 00:00:00 2001 From: Todd Rasband Date: Mon, 26 Mar 2018 11:55:28 -0600 Subject: [PATCH 06/10] made large changes and converted cart over to a class --- BrokenProblems/brokenLargestEven.js | 4 ++-- Cart/Part1-Setup-removeFromCart.js | 22 +++++++++++++++++ Cart/Part1-removeFromCart.js | 20 ---------------- Cart/Part2-calculateTotal.js | 37 +++++------------------------ Cart/Part3-updateQuantity.js | 37 ++++------------------------- Cart/Part4-addToCart.js | 37 +++++------------------------ Medium/bubbleSort.js | 2 -- Medium/lowestCommonDenominator.js | 20 +++++++++------- Problems/Palindrome.js | 4 ++-- Problems/hoisting.js | 0 Problems/letVarConst.js | 0 Problems/toTheMoon.js | 4 ++-- README.md | 17 +++++++++---- 13 files changed, 69 insertions(+), 135 deletions(-) create mode 100644 Cart/Part1-Setup-removeFromCart.js delete mode 100644 Cart/Part1-removeFromCart.js delete mode 100644 Medium/bubbleSort.js delete mode 100644 Problems/hoisting.js delete mode 100644 Problems/letVarConst.js 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/Cart/Part1-Setup-removeFromCart.js b/Cart/Part1-Setup-removeFromCart.js new file mode 100644 index 0000000..a99b0e9 --- /dev/null +++ b/Cart/Part1-Setup-removeFromCart.js @@ -0,0 +1,22 @@ +// 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 +}]; \ No newline at end of file diff --git a/Cart/Part1-removeFromCart.js b/Cart/Part1-removeFromCart.js deleted file mode 100644 index 72404f5..0000000 --- a/Cart/Part1-removeFromCart.js +++ /dev/null @@ -1,20 +0,0 @@ -// over the next few toy problems we will be building out a class that constructs a cart object that also includes a few methods to manipulate the data. -// 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 - - -[{ - 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 -}]; \ No newline at end of file diff --git a/Cart/Part2-calculateTotal.js b/Cart/Part2-calculateTotal.js index c6455e4..a5bbe09 100644 --- a/Cart/Part2-calculateTotal.js +++ b/Cart/Part2-calculateTotal.js @@ -1,31 +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. -// Have the function assume 7% tax rate if one is not passed in (look up default params). -// 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/Part3-updateQuantity.js b/Cart/Part3-updateQuantity.js index 984042b..554cae8 100644 --- a/Cart/Part3-updateQuantity.js +++ b/Cart/Part3-updateQuantity.js @@ -1,33 +1,4 @@ -// Below is an array of products that are in a cart. -// Write a function That will take in two parameters. -// One parameter is an object with the id of the item to update, and the quantity to set it to. -// The second parameter is the cart array to be updated. -// The function 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/Part4-addToCart.js b/Cart/Part4-addToCart.js index 29d95d3..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 function 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/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/lowestCommonDenominator.js b/Medium/lowestCommonDenominator.js index 40acf91..66ec694 100644 --- a/Medium/lowestCommonDenominator.js +++ b/Medium/lowestCommonDenominator.js @@ -14,32 +14,36 @@ const fractionsTwo = [[3, 7], [8, 12], [7, 45]]; function LCD(fractions) { let largestDenominator = 0; fractions.forEach((fraction) => { - if(fraction[1] > largestDenominator) { - largestDenominator = fraction[1]; + let [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) => { 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]; + + let 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; diff --git a/Problems/Palindrome.js b/Problems/Palindrome.js index ad4b70f..e4b8aad 100644 --- a/Problems/Palindrome.js +++ b/Problems/Palindrome.js @@ -8,5 +8,5 @@ // 'party trap' returns true // Extra Bonus -// Have it work even if some letters are uppercase -// Have it work even if some characters are non alphabetic ' " ! ? , +// Have it the function be case insensitive +// Have it ignore are non alphabetic characters ' " ! ? , diff --git a/Problems/hoisting.js b/Problems/hoisting.js deleted file mode 100644 index e69de29..0000000 diff --git a/Problems/letVarConst.js b/Problems/letVarConst.js deleted file mode 100644 index e69de29..0000000 diff --git a/Problems/toTheMoon.js b/Problems/toTheMoon.js index a587cd0..66a4eeb 100644 --- a/Problems/toTheMoon.js +++ b/Problems/toTheMoon.js @@ -9,5 +9,5 @@ // A piece of paper has a thickness of 0.0001. // The distance to the moon is 384400000 - - +// Bonus Challenge +// Use a while loop \ No newline at end of file diff --git a/README.md b/README.md index 29d660b..5301ac7 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ Later in the I would like to do one or who Schema toy problem. So specifically h
    • Day 1: This and Context
    • Day 2: Bob Ross Family Tree
    • Day 3: Broken - Vowel Counter
    • -
    • Day 4: Cart - Remove From Cart
    • +
    • Day 4: Cart - class setup/Remove From Cart
    • Day 5: None
    @@ -92,15 +92,24 @@ Later in the I would like to do one or who Schema toy problem. So specifically h
    • Day 1: None
    • Day 2: Cart - Calculate Total
    • -
    • Day 3: Cart - Update Quantity / Add to Cart
    • -
    • Day 4: Broken - Factorial
    • +
    • Day 3: Cart - Update Quantity
    • +
    • Day 4: Broken - Largest Even
    • Day 5: None
    ### Week 4
    • Day 1: Object.Assign
    • -
    • Day 2:
    • +
    • Day 2: Cart - Add to Cart
    • +
    • Day 3: Average Finder
    • +
    • Day 4: Broken - Bus Tracker
    • +
    • Day 5: None
    • +
    + +### Week 5 +
      +
    • Day 1: HTML (adobe)
    • +
    • Day 2: Palindrome
    • Day 3:
    • Day 4:
    • Day 5: None
    • From 40960b086e97bfb47baee2d0b9ce2fce224b1389 Mon Sep 17 00:00:00 2001 From: Todd Rasband Date: Fri, 30 Mar 2018 11:23:32 -0600 Subject: [PATCH 07/10] added onto readme --- .vscode/launch.json | 29 +++++++++++++++++++++++++++++ DailyScheudule.md | 4 ++++ Problems/letterFrequency.js | 13 ++++++++++++- README.md | 19 ++++++++++++++----- 4 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 DailyScheudule.md 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/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/Problems/letterFrequency.js b/Problems/letterFrequency.js index de31786..be07367 100644 --- a/Problems/letterFrequency.js +++ b/Problems/letterFrequency.js @@ -7,4 +7,15 @@ // Ignore Spaces // Bob Ross -> {b: 2, o: 2, r: 1, s: 2} -// taco cat -> {t: 2, a: 2, c: 2, o: 1} \ No newline at end of file +// 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/README.md b/README.md index 5301ac7..e5a3197 100644 --- a/README.md +++ b/README.md @@ -75,14 +75,14 @@ Later in the I would like to do one or who Schema toy problem. So specifically h
    • Day 1: none
    • Day 2: 45 Minute Fizz Buzz With '8 step Walk through'
    • Day 3: Broken - Swap Case
    • -
    • Day 4: Broken - Array's and Reference
    • +
    • Day 4: Broken - Array's and Reference(In prep for setState/immutability)
    • Day 5: None
    ### Week 2
      -
    • Day 1: This and Context
    • -
    • Day 2: Bob Ross Family Tree
    • +
    • Day 1: This and Context(In prep for props/binding)
    • +
    • Day 2: Bob Ross Family Tree (in prep for axios)
    • Day 3: Broken - Vowel Counter
    • Day 4: Cart - class setup/Remove From Cart
    • Day 5: None
    • @@ -99,7 +99,7 @@ Later in the I would like to do one or who Schema toy problem. So specifically h ### Week 4
        -
      • Day 1: Object.Assign
      • +
      • Day 1: Object.Assign(In prep for Redux)
      • Day 2: Cart - Add to Cart
      • Day 3: Average Finder
      • Day 4: Broken - Bus Tracker
      • @@ -108,8 +108,17 @@ Later in the I would like to do one or who Schema toy problem. So specifically h ### Week 5
          -
        • Day 1: HTML (adobe)
        • +
        • Day 1: HTML Adobe(In prep for Media Queries)
        • Day 2: Palindrome
        • +
        • Day 3: Letter Frequency
        • +
        • Day 4: None (Do the wireframe project planning for all day review)
        • +
        • Day 5: None
        • +
        + +### Week 6 +
          +
        • Day 1: None (PP kick off)
        • +
        • Day 2:
        • Day 3:
        • Day 4:
        • Day 5: None
        • From 0df596a5b0a06df8fe2f8043d4c1d8603b766fe7 Mon Sep 17 00:00:00 2001 From: Todd Rasband Date: Wed, 16 May 2018 11:06:38 -0600 Subject: [PATCH 08/10] ready to transfer --- Cart/Part1-Setup-removeFromCart.js | 37 +++++++++++---------- Medium/lowestCommonDenominator.js | 52 +++++++++++++++--------------- README.md | 14 ++++---- 3 files changed, 52 insertions(+), 51 deletions(-) diff --git a/Cart/Part1-Setup-removeFromCart.js b/Cart/Part1-Setup-removeFromCart.js index a99b0e9..cbfe5e1 100644 --- a/Cart/Part1-Setup-removeFromCart.js +++ b/Cart/Part1-Setup-removeFromCart.js @@ -3,20 +3,23 @@ // 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 -}]; \ No newline at end of file +[ + { + 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/Medium/lowestCommonDenominator.js b/Medium/lowestCommonDenominator.js index 66ec694..426827d 100644 --- a/Medium/lowestCommonDenominator.js +++ b/Medium/lowestCommonDenominator.js @@ -13,8 +13,8 @@ const fractionsTwo = [[3, 7], [8, 12], [7, 45]]; function LCD(fractions) { let largestDenominator = 0; - fractions.forEach((fraction) => { - let [numerator, denominator] = fraction + fractions.forEach(fraction => { + const [numerator, denominator] = fraction; if (denominator > largestDenominator) { largestDenominator = denominator; } @@ -24,7 +24,7 @@ function LCD(fractions) { const numberOfFractions = fractions.length; do { denominatorsAreDivisibleByCounter = 0; - fractions.forEach((fraction) => { + fractions.forEach(fraction => { const fractionsDenominator = fraction[1]; if (currentLCDToCheck % fractionsDenominator === 0) { denominatorsAreDivisibleByCounter += 1; @@ -36,39 +36,39 @@ function LCD(fractions) { } } while (denominatorsAreDivisibleByCounter !== numberOfFractions); - let commonDenominatorFractions = fractions.map((fraction) => { + const commonDenominatorFractions = fractions.map(fraction => { const numberToMultiplyBy = currentLCDToCheck / fraction[1]; fraction[0] = numberToMultiplyBy * fraction[0]; fraction[1] = numberToMultiplyBy * fraction[1]; return fraction; }); - return commonDenominatorFractions + 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/README.md b/README.md index e5a3197..b0a0bab 100644 --- a/README.md +++ b/README.md @@ -10,19 +10,17 @@ Doing these steps will add extra time onto the problem so you may want to give t // Step 1: Clarify - Understand the question -// Step 2: What data structures are needed +// Step 2: Create sample data -// Step 3: Create sample data +// Step 3: Solve Sample Data -// Step 4: Solve Sample Data +// Step 4: Function Signature -// Step 5: Function Signature +// Step 5: List code constructs -// Step 6: List code constructs +// Step 6: Pseudo Code -// Step 7: Pseudo Code - -// Step 8: Solve +// Step 7: Solve ## Broken Problems From 8d8a7026a795fb9d369db0900de368af60dcba16 Mon Sep 17 00:00:00 2001 From: rasbandit Date: Fri, 8 Jun 2018 11:53:24 -0600 Subject: [PATCH 09/10] moved readme around --- README.md | 105 ++++++++++++++++++--------------------- javascript-2-afternoon-3 | 1 + 2 files changed, 49 insertions(+), 57 deletions(-) create mode 160000 javascript-2-afternoon-3 diff --git a/README.md b/README.md index b0a0bab..0477c9d 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,53 @@ The intro and medium folders are just random toy problems that I have collected but are not really part of my new plan specifically. Part of my goal with this is to eliminate "advanced toy problems" and make it so every problem will have a variety of approaches and ways to optimize them. +## Purposed Toy Problem + +### Week 1 +
            +
          • Day 1: none
          • +
          • Day 2: 45 Minute Fizz Buzz With '8 step Walk through'
          • +
          • Day 3: Broken - Swap Case
          • +
          • Day 4: Broken - Array's and Reference(In prep for setState/immutability)
          • +
          • Day 5: None
          • +
          + +### Week 2 +
            +
          • Day 1: This and Context(In prep for props/binding)
          • +
          • Day 2: Bob Ross Family Tree (in prep for axios)
          • +
          • Day 3: Broken - Vowel Counter
          • +
          • Day 4: Cart - class setup/Remove From Cart
          • +
          • Day 5: None
          • +
          + +### Week 3 +
            +
          • Day 1: None
          • +
          • Day 2: Cart - Calculate Total
          • +
          • Day 3: Cart - Update Quantity
          • +
          • Day 4: Broken - Largest Even
          • +
          • Day 5: None
          • +
          + +### Week 4 +
            +
          • Day 1: Object.Assign(In prep for Redux)
          • +
          • Day 2: Cart - Add to Cart
          • +
          • Day 3: Average Finder
          • +
          • Day 4: Broken - Bus Tracker
          • +
          • Day 5: None
          • +
          + +### Week 5 +
            +
          • Day 1: HTML Adobe(In prep for Media Queries)
          • +
          • Day 2: Palindrome
          • +
          • Day 3: Letter Frequency
          • +
          • Day 4: None (Do the wireframe project planning for all day review)
          • +
          • Day 5: None
          • +
          + ## Problem Solving Below are steps that should be used for teaching how to solve toy problems. It is vitally important to use this on every toy problem you do from scratch. This teaches them how to break down a toy problem and identify its parts. This is also the exact same steps that should be followed when doing white board problems, Make sure the students know that! Help them to see the value in being clear with your communication and planning. Some steps seem to be not worth while but if a student is struggling with toy problems you should be able to help them see that their problem has to do with one of the steps. @@ -64,60 +111,4 @@ This is in no way a compleat or finished list. if there is a () next to the titl ## SQL Schema -Later in the I would like to do one or who Schema toy problem. So specifically how to build a table for the data you need. Not how to select from it. We spend enough time on how to get data, but not how to structure data. - -## Purposed Toy Problem - -### Week 1 -
            -
          • Day 1: none
          • -
          • Day 2: 45 Minute Fizz Buzz With '8 step Walk through'
          • -
          • Day 3: Broken - Swap Case
          • -
          • Day 4: Broken - Array's and Reference(In prep for setState/immutability)
          • -
          • Day 5: None
          • -
          - -### Week 2 -
            -
          • Day 1: This and Context(In prep for props/binding)
          • -
          • Day 2: Bob Ross Family Tree (in prep for axios)
          • -
          • Day 3: Broken - Vowel Counter
          • -
          • Day 4: Cart - class setup/Remove From Cart
          • -
          • Day 5: None
          • -
          - -### Week 3 -
            -
          • Day 1: None
          • -
          • Day 2: Cart - Calculate Total
          • -
          • Day 3: Cart - Update Quantity
          • -
          • Day 4: Broken - Largest Even
          • -
          • Day 5: None
          • -
          - -### Week 4 -
            -
          • Day 1: Object.Assign(In prep for Redux)
          • -
          • Day 2: Cart - Add to Cart
          • -
          • Day 3: Average Finder
          • -
          • Day 4: Broken - Bus Tracker
          • -
          • Day 5: None
          • -
          - -### Week 5 -
            -
          • Day 1: HTML Adobe(In prep for Media Queries)
          • -
          • Day 2: Palindrome
          • -
          • Day 3: Letter Frequency
          • -
          • Day 4: None (Do the wireframe project planning for all day review)
          • -
          • Day 5: None
          • -
          - -### Week 6 -
            -
          • Day 1: None (PP kick off)
          • -
          • Day 2:
          • -
          • Day 3:
          • -
          • Day 4:
          • -
          • Day 5: None
          • -
          \ No newline at end of file +Later in the I would like to do one or who Schema toy problem. So specifically how to build a table for the data you need. Not how to select from it. We spend enough time on how to get data, but not how to structure data. \ No newline at end of file diff --git a/javascript-2-afternoon-3 b/javascript-2-afternoon-3 new file mode 160000 index 0000000..fa86f7a --- /dev/null +++ b/javascript-2-afternoon-3 @@ -0,0 +1 @@ +Subproject commit fa86f7a5a0efad1db2e8afb918000f6b0eaa9a93 From 1ceff00dd24cfcf0ae52678977bf253ea2f737cd Mon Sep 17 00:00:00 2001 From: Travis Allen Date: Wed, 27 Jun 2018 15:02:32 -0600 Subject: [PATCH 10/10] Clarification in the bus tracker instructions --- BrokenProblems/brokenBusTracker.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/BrokenProblems/brokenBusTracker.js b/BrokenProblems/brokenBusTracker.js index d54e7ef..4399c8c 100644 --- a/BrokenProblems/brokenBusTracker.js +++ b/BrokenProblems/brokenBusTracker.js @@ -1,14 +1,14 @@ // 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.