Quiz
- For question 2, the reading said that we don't use ID. Does this mean "usually not use" or "we can't use"?
I appreciate your careful reading! The next part says:
While it's certainly possible to create IDs for dynamic elements and use them successfully, it's tricky and usually unnecessary. I suggest avoiding ID on all dynamic elements.
Which I meant as "usually not have IDs"
- what does .find() return?
Like pretty much all jQuery methods, it returns a "wrapped set" of the items it matches. We used
find
in CoffeeRun to find the desired checkbox, and we usedfind
in the Quizzes assignment to find the user's answer. - can you explain how the subtraction in the number sort works?
Sure. Let's take an example like this:
- Could you explain why strArray.sort(cmp) works when cmp taking parameters a and b. Are a and b every possible pair of strings in strArray that get passed into cmp and compared?
Well, not *every* pair (that's an n2 algorithm), but *any* pair. Let's do a very verbose example:
Let's try it on this 8 element array:
That yields 13 comparisons, not 64 and better than n log n = 3*8 = 24.