Ad
  • Custom User Avatar

    it also check if number is negative or not

  • Default User Avatar
  • Custom User Avatar

    limited testing. it's essentially correct, even if somewhat incomplete.

  • Default User Avatar
  • Custom User Avatar

    in js Boolean(" ") return TRUE and Boolean(undefined) return FALSE, if the condition throw a false condition the string will be a space string.

  • Custom User Avatar

    This guy has not taken a shower in years

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    Can think of it like this:

    • first, we set up way to handle all undefined cases

    • we'll be able to check and handle all other cases by combining the loop and if conditional

    • we can use guarded clause if that'll run only if the for loop doesn't return earlier

    • we put return undefined at the end of the code block

    • we know we need to return the value that is sequenced after the item

    • we can combine loop and conditional variable for COMBINED SET UP

    • when loop finds what it needs to find, we can tell it to modify variable outside of loop body

    • which means the next iteration runs

    • and that iteration - it contains the next value, which is what we're looking for

    • and then and there - we can use the changed variable outside of the loop function

    • and when that variable it's true and only then

    • we can just return that value, as it's the value right after the previous value

    • and the previous value was a match, equal to item

    • so if we return the value from the iteration that is right after that iteration that found the match

    • that'll always be the value we're looking for, given the problem specification

    • we need a loop that can iterate over any iterable, not just array

    • for...of... does that

    • now, in each iteration, we're getting the value

    • we check it against the item

    • if it is the item

    1. Understanding what for...of...loop is & what a guarded clause (if) statement is,
    2. Understanding how a SET UP can be achieved, by COMBINING a loop, and a conditional variable
    3. Understanding how RETURN STATEMENT can COMBINED with the above SET UP,
    4. Using these 3 understandings to create a LOOP that CHECKS what it needs to check, MODIFIES the VARIABLE when it needs to, and USES THE SET UP to RETURN when it's time and does NOTHING if no check passes, swhich is caught by the last statement, the guarded clause if

    It's probably best to go at these one at a time, and really get each item more deeply in a successive progression.

    If you didn't know any of this - and never saw the solution before - what would make solving it that way a 100x easier, is more or less:

    1. Knowing that for...of... exists (study your toolset, study knowing a lot of vocabulary and phrasing, study being proficient in the tongue you're using)
    2. Understanding what for...of... is in concept
    3. Understanding in general that different pieces of a language can be combined together in some useful fashion
    4. Understanding more specifically that conditional variable based on if, can be combined with a loop, in some useful ways
    5. Understanding how to do it, being well-practiced in combining such distinct features of a language, some solid and varied reps, deliberate practice and training at specifically just that small combination, one at a time
    6. Understanding what the problem is, in exact terms
    7. Being able to look for windows of opportunity in a problem, for openings that can be used to accomplish what we want to accomplish out of it
    8. Combining that ability with the toolset we learn, so we can be better and better at finding what we need to find because we have internalized the items that can match what we seek for
    9. Now, that's a lot - with practice, many points become fewer, connected points, which ultimately become one chunk of learned concepts and internalized training relating to the scope of that chunk and its connection to other chunks
  • Custom User Avatar

    Mad, you made use of IFFE and Closures.

    I had to take a deep look

  • Default User Avatar
  • Default User Avatar

    It isn't the best way haha, its terrible. I think maybe that is the point.

  • Custom User Avatar

    I would much prefer a solution from an actual human and not from the grandchild of Martians

  • Default User Avatar

    The question was to solve the Bob's problem not to build a 'castle'.

  • Default User Avatar
  • Custom User Avatar

    It adds nonsense on top of the starting code nonsense. It is not the best way of solving the problem.

  • Loading more items...