-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Troy Bradley Sprint Challenge #55
Troy Bradley Sprint Challenge #55
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey Troy. Things look good here man. I think you're on a really good pace. I'm really excited to see where you take the next couple of weeks. Pay attention to the comment I left about var, let, const. I recommend looking into what all three of those do and why they're different.
7. Object (including Arrays) | ||
|
||
#### What's so special about Arrays? | ||
1. Ryan **LOVES** them! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good answer! 👍
Closure is the end of the compiler's search for the value of a variable called inside a function. When the | ||
compiler is presented a variable (`x`) which is not declared in the same Scope as where it is called, it must | ||
search additional layers of Scope to find `x`. If the variable declaration is not found in any layer of Scope | ||
accessible to the function where `x` was called, an error will result. If it is, we have CLOSURE! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great explanation of Closure. Very thoroughly researched and understood here!
// Produces a new array of values by mapping each value in list through a transformation function (iteratee). | ||
// Return the new array. | ||
const newArray = []; | ||
each(elements, (item, index) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great reuse of the each
function here!
@@ -28,18 +36,22 @@ const cacheFunction = cb => { | |||
|
|||
/* ======================== Recursion Practice ============================ */ | |||
const reverseStr = str => { | |||
// reverse str takes in a string and returns that string in reversed order | |||
// The only difference between the way you've solved this before and now is that you need to do it recursivley! | |||
var first = str[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use const
until you're not able to. Then use let
. There is much more power in understanding const and let and their proper use cases these days. Using var
tells me you want to be able to redefine the variable in the same scope later on. This idea of overriding
variables is now solved with the new keywords.
}; | ||
// based on https://stackoverflow.com/questions/4859208/recursive-string-reversal-function-in-javascript | ||
|
||
const checkMatchingLeaves = obj => { | ||
// return true if every property on `obj` is the same |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I never was able to give a live lecture going over this function. I did, however, link a video out to our Lead TA explaining the solution. I'd recommend looking at it, as it may help you out next week!
// Flattens a nested array (the nesting can be to any depth). | ||
// Example: flatten([1, [2], [3, [[4]]]]); => [1, 2, 3, 4]; | ||
each(elements, element => { // call each function to iterate over the array | ||
elements = flatten([].concat([], ...elements)); // flatten by breaking out nested arrays as we recursively call flatten function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, That is an amazing solution! I'm going to have to look into this and see if there are any edge cases that could potential pop up, for now, I'd tally this one up as my favorite solution to flatten.
Quite the learning experience. So this is what it's like to be a coder!