Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialdon bencilao
4,153 Pointssort and poping the values
I get why he is push the values to blanks variable but I don't get why he is sorting them out and poping the last value.
3 Answers
austenpayan
10,218 PointsHey don,
The reason he is popping off the last value is because the sort method will rearrange the array of true or false (boolean) values so that all of the false values will be in the front of the array and all of the true values will be at the back of the array.
Since the .each loop is returning true every time there is a blank, if there is a blank, the last item in the array will be true. Which makes the function containsBlanks return true, which we can then use in other parts of the code in conditionals to disable the submit button if containsBlanks is true (because we dont want to submit if there are blanks).
Hope this helps a little =}
don bencilao
4,153 Pointsit pops out just one value right?
if there is no empty field then the array will be filled with false values and the so the containsBlanks will return false? -_- rawr!
austenpayan
10,218 PointsPrecisely! it pops out the very last value. So if there are ANY true values, a true value will be popped out. If there are no true values, then a false will be popped out, and the entire function will return false.
If i remember correctly he later used the function containsBlanks in a conditional but he put a "!" before the name. a "!" will negate the function, so that if the function returns true (theres blanks) then later on in the conditional the "!containsBlanks()" will make it false. But if containsBlanks returns false (no blanks), then "!containsBlanks()" will return true, and thus activate the submit button.
don bencilao
4,153 Pointsthanks Austen Payan!
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsGreat explanation!