menu
joshmrallen
Complete the Angela Yu Web Developm... Star this Commitment
Day 17 of 17

joshmrallen commits to:
Spend at at least 8 hours a day or more to complete the Angela Yu Web Development Course on Udemy.
17
0
No more reports due
Details
My Commitment Journal
A-Run-for-Joey
A-Run-for-Joey
March 7, 2020, 1:41 PM
Good job.
joshmrallen
joshmrallen
February 29, 2020, 10:12 PM
Conclusion:
And this is it. I started out with the intention of completing a udemy 'bootcamp' while at the same time seeing how soon I could start an actual bootcamp near me physically, in the real world.

I did and it turned out they had prework which I've been working on ever since I got accepted. Luckily, the subjects and assignments covered in the udemy bootcamp overlapped!

I'm going to make a new commitment to finish this prework by next Friday.
joshmrallen
joshmrallen
February 29, 2020, 10:02 PM
Here's Friday 2/28/2020:

Continuing on with the next section:
Introduction to Enumerables


key terms
mapping: to "poll" every member in a collection and collect the results into a new collection


reducing: to "poll" every member in a collection and join those poll's results together into a single value through a process called "reducing"




"wrapping' - I don't think I defined this for myself. The content seems to assume you can figure out what they mean by wrapping -- as a kind of pedogical word play to help you visualize what's happening. By wrapping, they mean to put something within brackets/parentheses/curly braces to create either a method or collection object (like an array, hash, etc)


Enumerable
enumerable is a ruby-specific term for any built-in method that:
1. iterates through each element in a collection (array, hash, etc)
2. tests each element or uses each element to return a result
3. returns a new collection of those returned results or accumulates those returned results into a single value


The word enumerable (for these methods like .each etc) comes from the verb, enumerate, which means to mention a number of things, one by one. The latin root enumerat, meaning 'count out' (e for ex and numerat from numerus (meaning number).


There's a general template for all enumerable methods:


1. give a collection
2. based on the number of items, visit each one by its location int he series (this is the ex numerus part - count out)
3. Do some work or test the elements or pairs in the collection (why does this definition mention 'pairs' all the time? Doesn't have to, we know to apply it to arrays of arrays, etc.
4. Depending on the job:
1. accumulate those elements after whatever we did to them into a new collection
2. or determine a special value (maximum/minimum, condition: boolean conclusion: false if no truthy values, true if all true or perhaps true if no values were truthy, etc)


The text refers to this template as the "character" of all enumerable methods. like a personality?


Pseudocode - already think in these terms thanks to college CS classes




Next:
Introduction to Map and Reduce Lab


this lab is going to have me build my own versions of map and reduce methods


remember that DRY means "Don't Repeat Yourself"


Map:
comes from mathematics where it means to take a variable, plug it into an equation and get a result


Reduce:
basically the idea that you cook something down (apply work) and use what's left over


all map methods return a new array
all reduce methods return a value


Create the following methods:


map_to_negativize(source_array)
returns an array with all values made negative


map_to_no_change(source_array)
returns an array with the original values
? what does this mean exactly? just return source_array?


map_to_double(source_array)
returns an array with the original values multiplied by 2


map_to_square(source_array)
returns an array with the original values squared






reduce_to_total(source_array, starting_point)
returns a running total when given a starting point
starting point is a number to add the values of the array to
returns a running total when not given a starting point
need to use a default in the parameter:
reduce_to_total(source_array, starting_point = 0)
worked!


reduce_to_all_true(source_array)
returns true when all values are truthy
returns false when any value is false -- check for this at the top of the if statement
worked!


reduce_to_any_true(source_array)
returns true when a truthy value is present
returns false when no truthy value is present
worked!






Next!
Generalized Map and Reduce Lab


* avoid duplication by using blocks
* are these different from code blocks I'm thinking of?
* ah, this is a Ruby specific term different form the general concept of a block of code
* two ways of construct blocks
* wrap the code in curly braces! {}
* used only when the code is one expression
* don't need return keyword
* use the keywords: do ... end
* used when the code takes multiple lines
* last line of do...end block will be the return value
* start by using do...end blocks
* makes it easy to add debugging lines for printing out values later
* once everything's correct, ok to switch to curly braces {}
* execute a block from within a method
* use the yield keyword
* purpose of the yield keyword
* yield executes the block passed into the method
* it's basically the 'return' keyword except for these blocks
* Use it inside of a method you plan to use with blocks?
* oh, a block is meant to be used with a method call -- VERY IMPORTANT TO KEEP IN MIND!!!!
* IT'S ONLY EVER USED WITH CALLS TO METHODS, NOT THE INSIDE CODE OF THE METHOD
* that's why it's like you're passing the arguments from inside the method to the block
* the method is the general instructions for what you want to happen
* you plan for it to take blocks as part of its usage and use yield for the express purpose of using blocks
* it yields the result of the code inside of the method to the block
* ohh, so not like return -- you use yield to pass code to the block...right?
* so yield calls the block
* so yield can be or actually is basically a placeholder for the block code
* when the code reaches 'yield', the code inside the block gets executed. when the code inside the block finishes, the execution of the method continues.
* the block is used to customize the results and basically do anything you want without declaring another method
* suddenly the funny term hashketball is starting to make more sense
* it's lesson 95 and I'm almost there. 9 more to go!
* parameters
* parameters for blocks are called block-parameters
* use pipe character instead of parentheses: | |
* multiple block parameters: separate with a comma like regular parameters
* pass data between methods and blocks
* then, when you call a method, immediately proceed with do, then the block parameter(s) between pipes, the code, and then close it with end
* it's cool because no matter how many arguments the method takes, you just need one block-parameter to handle it.




example:


1. def make_sandwich(element1, element2)
2. base = "A #{element1} and #{element2}"
3. yield(base)
4. end
5.
6. make_sandwich("gator", "gumbo") do |innards|
7. "#{innards} on rye"
8. end #=> "A gator and gumbo on rye"






this can be written using curly braces {} since it's one expression and very simple:


make_sandwich("gator", "gumbo") { |innards| "#{innards} on rye" }
#=> "A gator and gumbo on rye"






Lab:
write a generalized map and reduce method


* both take a a bock
* both need data passed between the method and the block


map - all the methods we did last lab, but now with just one method and blocks -- as per the tester
map(array) {|a| a*a}
1. Arguments
1. source array
2. yields(each item in source array)
3. returns
1. array


Ok, this is annoying. They showed bascially what yield is but didn't show us exactly how its used. But they did say the goal is to be able to look up in the documentation. Jesus.




Ok, so yield takes parameters yo.
it should be taught this way:
yield is a stand-in for block and will pass values to block.
the value passed is basically an argument -- so yield(value) is what you'll most often be using.


Then you can use block to basically add your own expressions




reduce
1. arguments
1. source array
2. starting value default to 0
2. yield(each item in source array)
3. returns a value


Ah hah, I should have had an if statement checking if a starting_point was provided. Tyler on learnco guided me:


def reduce(source_array, starting_point = nil)


if starting_point
new = starting_point
i = 0
else
new = source_array[0]
i = 1
end

while i < source_array.length do
new = yield(new, source_array[i])
i += 1
end
return new

end




Big help!


Next!
Enumerable Family Tree


* map and reduce are built-in methods in the Array Class
* use map to transform an array
* [10, 20, 30, 40].map{ |num| num * 2 }
* use reduce to reduce an array to a value
* [10, 20, 30, 40].reduce(0){ |total, num| total + num}
* [10, 20, 30, 40].reduce(100){ |total, num| total + num }
* use Ruby documentation to learn more about other variations on map an reduce
* Now I can understand how to use most of the methods in the documentation now!
* At first, the blocks were confusing
* but now that I know what they are and what they do, it really opens the methods up to what I could do with them
* use select and reject to filter an array
* .select returns an array containing all elements for which the given block returns a true value
* .filter does the same thing
* [10, 20, 30, 40].select{ |num| num > 25 }
* .reject returns an array for all elements for which the given block returns false
* [10, 20, 30, 40].reject{ |num| num > 25 }
* memorize a list of enumerables
* all?
* Everything "tested" by the block returns truthy
* any?
* Did anything "tested" by the block returns truthy
* collect
* A synonym for map
* count
* Which elements satisfy the block or, without block, how many elements are there?
* detect
* Which element satisfies the block first. Does the same thing as find.
* find_all
* Which elements satisfy the block?
* find_index
* What is the index of the first element to satisfy the block?
* max
* What's the highest value?
* max_by
* What's the highest value based on some property of the element?
* min
* What's the lowest value?
* sort
* Put the values in order




Next!
Each: The unexpressive Enumerable


* .each is the root of all the mapping/reducing-like methods
* use each to work with an array
* explain why each is the least-expressive Enumerable
* it should be use the least out of all the methods
* because it's the least-expressive
* .each is generic
* you can reinvent all those other methods using .each
* shouldn't do this because it skips the documentation part of programming and leads to poor readability
* it's not as easy to see what a method that has .each is doing as one that using a more specific method
* code should communicate first and work second
* when to use .each
* enumerate a collection but not transforming the data
* when you aren't sure which Enumerable you should use
* best use is to print to the screen
* though you can always just use p with the result of a more specific Enumerable
* variants of .each
* each_cons
* each_entry
* each_slice
* each_with_index
* each_with_object (a cousin of reduce)
* .each is the most flexible, but also the least expressive
* most of the time you'll be using map and reduce
* use when you aren't sure which other methods you should use




Next!
Hashes & Enumerables


Ah, the real goal -- using enumerables with hashes. the Hash class has all the same enumerables as Array except some are less useful than they are for Arrays


* use .each and .each_pair to print out a hash
* use reduce to create a transformed hash
* use reduce to resolve a value from a hash
* many programmers forget to return the 'memo' at the end and have a tricky bug because of it
* use the hash, the each, and the hash-relevant each_pair to help
* print out a hash using .each and .each_pair (see below for example hash)


**the first block parameter is conventionally called 'memo' -- saw this in the previous lab's tester, but didn't know why it was chosen for the block parameter


example:


bands = {
joy_division: %w[ian bernard peter stephen],
the_smiths: %w[johnny andy morrissey mike],
the_cramps: %w[lux ivy nick],
blondie: %w[debbie chris clem jimmy nigel],
talking_heads: %w[david tina chris jerry]
}


bands.each{ |pair| p pair}
#=>
# [:joy_division, ["ian", "bernard", "peter", "stephen"]]
# [:the_smiths, ["johnny", "andy", "morrissey", "mike"]]
# [:the_cramps, ["lux", "ivy", "nick"]]
# [:blondie, ["debbie", "chris", "clem", "jimmy", "nigel"]]
# [:talking_heads, ["david", "tina", "chris", "jerry"]]




.each_pair is more expressive:


it does the same thing in this case


if you want to change anything, reduce is better:


bands.reduce({}) do |memo, pair|
p memo #First block parameter
p pair #Second block parameter
memo #Return value for the block. It becomes the memo in the next go-around
end


{}
[:joy_division, ["ian", "bernard", "peter", "stephen"]]
{}
[:the_smiths, ["johnny", "andy", "morrissey", "mike"]]
{}
[:the_cramps, ["lux", "ivy", "nick"]]
{}
[:blondie, ["debbie", "chris", "clem", "jimmy", "nigel"]]
{}
[:talking_heads, ["david", "tina", "chris", "jerry"]]


our 'accumulating' hash called memo (the first block parameter) is the thing we need to update. but keys and values are returned as 2-element arrays in each call to the block.


how do we split each array into key and value?


we could use pair[0] and pair[1]


Ruby has a nicer way to do this kind of work called: "destructing assignment." This means using parentheses for that block parameter, and listing key and value, separated by a comma.


bands.reduce({}) do |memo, (key, value)|
p memo #first block parameter
p key #Second block parameter
p value #Second block parameter
memo #Return value for the block, becomes the memo in the next iteration
end


1. #=>
2. # {}
3. # :joy_division
4. # ["ian", "bernard", "peter", "stephen"] ... etc.




"Thanks to destructuring assignment (using the parentheses), we crack open the Array that was in the pair parameter and put element 0 in key and element 1 in value. With this in place, it's easy to create that alphabetized roster."


sorted_member_list = bands.reduce({}) do |memo, (key, value)|
memo[key] = value.sort
memo
end


printing them out:


p bands
p sorted_member_list


{:joy_division=>["bernard", "ian", "peter", "stephen"], :the_smiths=>["andy",
"johnny", "mike", "morrissey"], :the_cramps=>["ivy", "lux", "nick"],
:blondie=>["chris", "clem", "debbie", "jimmy", "nigel"],
:talking_heads=>["chris", "david", "jerry", "tina"]}








Another example:


With Hashes, we also use reduce to accumulate to a single value. Let's find first-most alphabetical band member of the entire Hash


bands = {
joy_division: %w[ian bernard peter stephen],
the_smiths: %w[johnny andy morrissey mike],
the_cramps: %w[lux ivy nick],
blondie: %w[debbie chris clem jimmy nigel],
talking_heads: %w[david tina chris jerry]
}

firstmost_name = bands.reduce(nil) do |memo, (key, value)|
# On the first pass, we don't have a name, so just grab the first one.
memo = value[0] if !memo

# Sort that array of names
sorted_names = value.sort

# If string comparison says the sorted name of the array is earlier than
# the memo, it becomes the new memo.
memo = sorted_names[0] if sorted_names[0] <= memo

# Return the memo as per reduce rules
# (Try adding 'p' in front of memo to see how it changes as the enumerate the
# pair of the hash!)
memo
end
p firstmost_name

"andy"


Master .reduce to transform a given hash into a new hash is a sign of a comfortable ruby programmer.




time for a quiz!
Ruby Enumerables Quiz


quizes have challenges now!


1st challenge:
use .map


lunch_menu.map {|item| "#{item}!" }
#adds an exclamation point to each item in the array lunch_menu


2nd challenge:
use .collect ....?


remember that .collect is a synonym for .map


variable, nums
set equal to an array of numbers
nums = [1,2,3,4]


enumerate of nums and return a new array of squares


nums.map{|n| n*n}
remember it's the same as .map, so:
nums.collect{ |n| n*n }


3rd challenge:
use .select


select: returns a new array containing all elements of the array for which the block returns a true value


nums = [2,4,3,5,7,6,9]


find all even numbers:


nums.select{|n| n % 2 == 0 }






4th challenge


use .find to return the first array element that's an odd number


nums = [2,4,3,5,7,6,9]


nums.find { |n| n % 2 == 1 } #this would work
nums.find{ |n| n.odd? } #this would also work




5th Challenge


use .include?


use .include? to check and see if an array includes a specific string


array_of_strings.include?("Maru) #.include? returns index if you provide a block instead of an argument




and done!


On to the labs now:


Reverse Each Word Lab


* understand the return value of the .each method
* use the .collect method
* understand the .collect method
* understand the return value of the .collect method
* use the return of collect for further operation


Instructions:
* write a method called reverse_each_word that takes in a string argument of a sentence and returns that same sentence with each word reversed in place.
* first make the method using .each
* then make the method using .collect
* notice the difference


example:


reverse_each_word("Hello there, and how are you?")
#=> "olleH ,ereht dna woh era ?uoy"


you can't use enumerators on a string, you must turn the string into an array first. How do you do that?


how do you reverse each word and return them? .each returns the original array but other enumerators don't


Ah hah, the tester doesn't test for .each, so screw that. full speed ahead with .map!


Ok, looks like I can use .collect in the whole method and that'll pass the lab.


And that's it:


def reverse_each_word(string)

string_array = string.split

reversed_words = string_array.collect {|word| word.reverse}

reversed_string = reversed_words.join(" ")

return reversed_string

end




Next lab:
Cartoon Collections Lab


Here we go!


* practice more array iteration with with enumerator methods like .collect or .map, .find, and .include?
* build methods and control their return values
* practice if/else statements for control flow


Instructions:
4 Methods:
* roll_call_dwarves
* Argument: array of dwarf names
* print out each name in number order using puts
* wtf is number order? the index order?
* looking at the tester, it explains much better:
* it means you create a numbered list, doesn't matter what the order of the dwarf names is -- just make sure the names are listed with numbers: 1. Dopey, 2. Grumpy, 3. Bashful, etc.
* I'll try it with new lines, all as text
* look into the each_with_index method
* use each_with_index block to add each element's index + 1 to the string with interpolation
* then use .join(", ") -- delimiter is comma and space?
* not necessary with each_with_index
* each_with_index worked very well
* summon_captain_planet
* argument: array of planeteer calls
* planeteer_calls = ["earth", "wind", "fire", "water", "heart"]
* Capitalize the first letter of each element
* Add an exclamation point to each
* returns:
* ["Earth!", "Wind!", "Fire!", "Water!", "Heart!"]
* .map or .collect (they're the same)
* long_planeteer_calls
* arguments: array of planeteer calls again
* return true if any of the calls are longer than four characters
* .map it, comparing each element:
* if element.length > 4 return true else return false
* as soon as it hits an element with more than 4 characters, it's going to return true, which is what we want. "tell us if any of the calls are longer than 4"
* no need for else statement -- since return true would break and end the method, if there are no true's, it'll finish iterating and go on to the return false line.
* looks like I don't need .map -- .any? seems perfect
* elements.any? { |call| call.length > 4 }
* worked great!
* find_the_cheese
* arguments: array of strings
* returns:
* first string that is a type of cheese
* nil if there's no cheese in the array
* nil is falsy right? if .include? returns nil, that would be the same as returning false? or no?
* look at .include? method
* .map of cheese array
* block: |cheese| passed_array.include?(cheese)
* no .map, just a while loop and if statement




and this is how you achieve 2 objectives for a string array with one .map call:


planeteer_calls.map do |e|


e.capitalize + "!"


end






def find_the_cheese(say_cheese)
cheese_types = ["cheddar", "gouda", "camembert"]
index = 0
while index < cheese_types.length do
if say_cheese.include?(cheese_types[index])
return cheese_types[index]
end
index += 1
end

end
joshmrallen
joshmrallen
February 28, 2020, 6:30 AM
Here's Thursday:

Had to take care of some FSA stuff last night.

referring to yesterdays notes to continue with this "Green Grocer" lab.

Green Grocer Lab
 
Goals:
- translate data from AoH to AoH
- perform calculations based on AoH data
- write a set of methods to handle the different pieces of the checkout process and "wrap" them all inside of a 'checkout' method
 
Ohh, Nth order means the highest order. First Order is the simplest methods that we use to make a nice, easy to read method.
 
Have to consult the readme for the inputs/outputs to each method
 
Methods to make
1. find_item_by_name_in_collection(name, collection)
1. arguments
1. name: string for name of the item to find
2. collection: array of the items to search through - actually it'll be an array of hashes
2. return
1. nil if no match
2. the hash of the item if a match is found between name string and hash's :item key value
3. success
2. consolidation_cart(cart)
1. arguments
1. array of hashes
2. return
1. a new array with every unique item from the original
- every item has a new :count attribute (aka, key)
- every item's :count is at least 1
- item's :count equals the total number of instances of the same item
3. Oh yeah, I can use the first method I made
1. But actually not
2. to use the first method, I'd need a counter added and code to remove the duplicates after they're found so that I don't incorrectly increment the counter
1. Should I add them to that first method or just make the while loop all over again?
3. Actually, I think I really can use the find_item_by_name_in_collection
1. for ease of understanding, I'm going to call the parameter array something else: array_of_item_hashes
2. each hash in the array will always have a :item key, so I can use that for the argument for find_item_by_name_in_collection
3. And since there will be more than one item in the array, I need to use [index] with the array, chaining on :item to access that specific item name
1. but this is only the name, not the hash
2. so if I check each hash in the array, I will for sure find at least 1 hash with that :item
1. Have a counter variable initialize to 0 inside of the loop so it will always reset to 0 for the next [index][:item]
1. Having found it, increment counter to 1
1. find_item_by_name_in_collection returns a hash
2. loop with common index
3. set index for new AofH equal to a call to the method at the same index
4. make a new loop after that operation to find duplicates
1. now it's easier to visualize because you're comparing the name of cons_cart to the "raw" array
2. oh, now I can initialize the counter to 0. It will increment to 1 no matter what because we just got it from the array and we know it's there. So no matter how the loop runs, it will increment to 1 without a doubt.
 
 
def consolidate_cart(array_of_item_hashes)
        
        cons_cart = {}
        index = 0

        while index < array_of_item_hashes.count do
             
            cons_cart[index] = find_item_by_name_in_collection(array_of_item_hashes[index][:item], array_of_item_hashes)
            
            cons_cart[index][:count] = 0

            search_index = 0
            while search_index < array_of_item_hashes.count do

                    if cons_cart[index][:item] == array_of_item_hashes[search_index][:item]
                            cons_cart[index][:count] += 1 #I had accidentally typed counter instead of count
                            #array_of_item_hashes.delete_at(search_index) DON'T ACTUALLY NEED THIS! IT WORKS FINE WITHOUT IT!!
                    end
                    
                    search_index += 1
            end

            
            
            index += 1
        end


end

 
Got this error:
  1) Grocer #consolidate_cart adds a count of one to each item when there are no duplicates
     Failure/Error: consolidated_cart = consolidate_cart(cart)

     TypeError:
       no implicit conversion of Hash into Integer
     # ./grocer.rb:51:in `pop'
     # ./grocer.rb:51:in `consolidate_cart'
     # ./spec/grocer_spec.rb:52:in `block (3 levels) in <top (required)>'
i was using pop incorrectly -- removes from end, but needed to specify location to remove from the array, but it turned out I didn't even need to remove the element.
it said it was returning nil and it turned out I had typed 'counter' instead of 'count'

Next method!
apply_coupons method

1. arguments
1. array of item hashes
2. array of coupon hashes
2. returns
1. a new array whose elements will be a mix of:
1. item hashes
2. item with coupon hashes (depending on coupon hash array)

so this next method takes an array of item hashes and an array of coupon hashes:
apply_coupons(items, coupons)

1. the coupon hashes will all be the same type
1. :num => number, :cost => cost
2. first use consolidate_cart method on the passed array and store it
1. cart = consolidate_items(items)
3. the method searches through the item array and finds an item matching an item in the coupon array
4. Make an item w/ coupon hash
1. item w/ coupons will be hashes that get added to the end of the original array of item hashes
2. set new_array = items, then add the item w/ coupon hashes
3. item_w_coupon = {}
1. item_w_coupon[:item] = "#{coupon[:item]} W/ COUPON"
2. item_w_coupon[:price] = coupon[:cost] / coupon[:num]
3. item_w_coupon[:clearance] = true
4. item_w_coupon[:count] = coupon[:num]
5. update the array item's num attribute if there are left over items
1. if item[:count] > coupon[:num] {item[:count] -= coupon[:num]} end
6. otherwise, if there are none left, remove it from the new_array
7. add the new item w/ coupon hash to the new_array:
1. new_array.push(item_w_coupon)
2. this didn't work for some reason -- had to set the hash equal to the clearance_cart.count location. Adding a new item when the if statement is true, this number will grow with each iteration.
8. increment index and repeat for multiple elements inside of coupon
9. return new_array


I will need to use the consolidate_cart method on the passed array of items.
            I didn't need to. The test did that for me. I commented that part out.


Next!
two more to go!
First one:
apply_clearance method

1. Arguments
1. Array of item hashes
2. Returns
1. a new array where every unique item from the original array has its price reduced by 20% when its :clearance attribute is 'true'

apply_clearance(cart)
1. check to see if test already runs consolidate_cart
1. yes, the test does, so I'll keep that out of this method
2. initialize new_array by setting it equal to cart
3. Iterate through cart
1. look for cart[index][:clearance] == true
1. Find the new price and update :price
2. set new_array[index][:price] *= 0.80        #keep in mind you need to put a zero in front of the decimal for any float no matter what language you're coding in
1. can I use round(2) with an operation? irb time
2. holy shit you can! at least in irb. wonder if this'll work on learn.co here
3. (price *= 0.80).round(2)
4. Testing
1. the booleans must be written as strings. changing mine to strings.
2. nope they're definitely strings because the if statement is ignoring the false's.
3. But the tests are working for the clearance items.


Aw man, I've been racking my brains on this all day. Finall succombed to watching the video they give a link for:
step by step for apply_clearance:
def apply_clearance(cart)
counter = 0
while counter < cart.length
if cart[counter][:clearance]
cart[counter][:price] = (cart[counter][:price] - (cart[counter][:price]*0.20))
end
counter +=1
end
end

Turns out it was an issue with the test that affects some students and not all! Spoke to a trainer named MAtteo who helped me out and instructed me on how to change line 202 of the test to:

expect(clearance_applied_cart[0][:price]).to be_within(0.1).of(2.40)

as opposed to the original
expect(clearance_applied_cart.first[:price]).to be_within(0.1).of(2.40)


anyways, on to the next, and last, one!
checkout method
1. arguments
1. array of item hashes
2. array of coupon hashes
2. returns
1. cart total as a float

checkout (cart, coupons)
consolidated_cart = consolidate_cart(cart)
coupon_applied_cart = apply_coupons(consolidated_cart, coupons)
clearance_applied_cart = apply_clearance(coupon_applied_cart)

#Find the total by iterating through the final cart -
# --multiply each item hash's price by its count
# ---accumulate in a total variable
# ----return total
index = 0
total = 0

while index < clearance_applied_cart.count do

total += clearance_applied_cart[index][:price]*clearance_applied_cart[index][:count]

index += 1
end

#If total is over $100, take additional 10% off the total
if total > 100
total *= 0.90
end

return total
end


got errors referencing spec file lines:
1. 265
2. 277
3. 286
4. 293
5. 301
6. 324

I think it's my consolidated method -- the counts are incorrect because I didn't account for the loop encountering the same item and looping again.

Ok, refactored my code according to the walkthrough video and that fixed a lot of problems.

I had definitely made it all more complicated than it had to be.

so the last issues:

I had a mistake in the consolidate_cart method and a mistake in the apply_coupon method that led to the checkout method not working.
I didn't account for coupons being empty.

everything works now!
walkthrough helped tremendously, of course.


good god that's finally over. and a good lesson for why it's important to have someone look at your code with you, at each stage to confirm it's doing what you expect it o.

Next Section:
Introduction to Enumerables

  • Feb 13, 2020
  • Feb 13, 2020
  • Feb 13, 2020
  • Feb 13, 2020
  • Feb 13, 2020
  • Feb 13, 2020
  • Feb 13, 2020
  • Feb 13, 2020
  • Feb 13, 2020
  • Feb 13, 2020
  • Feb 13, 2020
  • Feb 13, 2020
Displaying 1-4 of 17 results.
February 28
Successful (referee feedback expired)
Success
No report submitted
February 27
Successful
Success
Success

A-Run-for-Joey
A-Run-for-Joey
- Referee approval report
joshmrallen
joshmrallen
- Committed user success report
February 26
Successful
Success
Success

A-Run-for-Joey
A-Run-for-Joey
- Referee approval report
joshmrallen
joshmrallen
- Committed user success report
February 25
Successful (referee feedback expired)
Success
No report submitted
Recipient of Stakes
Anti-charity (Abortion: Americans United for Life)
To change the Recipient of Stakes for your Complete the Angela Yu Web Developm... Commitment, enter their email address or stickK username below.
Total at stake: $85.00
Stakes per period: $5.00
Remaining Stakes: $0.00
Total Money Lost: $0.00
Referee
Supporters
.
+
Server IP 10.0.0.224
Portal Id 0
User Id 0
Unix Timestamp 1734898615
Current Timezone GMT
Server encoding: utf-8
Assets folder: https://static.stickk.com/yii-assets/209680c5
Payment Type PRODUCTION
Your feedback has been sent. Thank you!
This website uses cookies to ensure you get the best experience on our website. Read our Privacy Policy
Loading...