Ad
  • Custom User Avatar

    split(" ") --> need a space " ", if closed "" will break down everything into a single character not whole word example: "hello world".split(" ") --> ['hello', 'world' ] "hello world.split("") --> [
    'h', 'e', 'l', 'l',
    'o', ' ', 'w', 'o',
    'r', 'l', 'd'
    ]

    hint: join() is not needed to solve this but doesn't mean your approah is wrongs and might need it to get rid of spaces...(haven't ran code but seems you're getting rid of spaces with loop)

    Sooo...
    with join() the default will join every thing with a "," inbetween example H,e,l,l,o,'',W,o,r,l,d

    with no space chosen ("") as how to join the split "hello world".split(" ").join("") --> HelloWorld as one word

    with space chosen (" ") as how to join the split "hello world".split(" ").join(" ") --> hello world

    *Note that "hello world".split("").join("") will return the same becasue of the space when split into single characters
    *BUT! with this you need to split into seperate words so..

    "what (3 spaces) ever sentence".split(" ")
    (put (3 spaces) to represent becasue when submitted this reply it took away spaces! ugh!)
    --> will split all the whole words and spaces into thier own index like [ 'what', '', '', 'ever', 'sentence' ] and join(" ") with a space inbetween ..."what ever sentence"...join("") --> "whateversentence"

    hope this helps refactor easier :)