Ad
  • 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

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

  • Default User Avatar

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

  • Custom User Avatar

    If the item is found the next value will be return (i.e. return x) on the next loop.

  • Default User Avatar

    I think he thinks n>0 is a safety check to make sure the argument passed isn't 0 or negative. I don't think he realizes it's effectively the break condition of a while loop.

  • Custom User Avatar
  • Custom User Avatar

    "Square it and you'll get the nearest square number."

    Square it and you'll get the square of the nearest natural number - not necessarily the nearest square number.
    They are different things and not actually the same.

  • Default User Avatar

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

  • Custom User Avatar

    It breaks when end can legally be 0 though.

    Better ( now; it hasn't always been available ) is function friday13(start,end=start). See MDN.

  • Custom User Avatar

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

  • Custom User Avatar

    what's your point? his expression is to call the function recursively until it hits zero, then it returns remaining string, sooooo, yeah... he could have replaced n>0 with just n and worked the same...

  • Custom User Avatar

    Both those tests expect false (at least in javascript), what are you talking about?

  • Default User Avatar

    you're just a jerk, actually:

    WHAT IS a palindorme? Certainly NOT "abcabc"!

    read the description and try to understand what you read, before making such stupid comments.

  • Default User Avatar

    you're in troll-mode or what?

    You choose one of the cases that is NOT a palindrome. But sure, you understand the description, yes. I'll put my life in your hands without the least doubt about that...

  • Default User Avatar

    ... 8-o

    Seems like you didn't understand what you were asked to do, then... The description is perfectly clear about that.

    your task is to determine if that string can be a palindrome >>>if we rotate one or more characters to the left.<<<

  • Loading more items...