Ad
  • Default User Avatar

    It's only one loop!

    One loop deep, maybe. How can you sort() a thing without looping over it? And I'm out of my league so I'll just ask: does str1.split('') provide a new view into existing data, or does it have to loop over and copy data piece by piece into a new structure?

  • Default User Avatar

    Just take a look at how many times the function is being called, and if you're not returning anything, it can't call undefined("some string"), which is why you're seeing the error.

  • Custom User Avatar

    it works correctly in JS. The task is a bit unusual, that's all.

  • Custom User Avatar

    but instead if throws a 'createMessage is not a function error'

    It may sound surprising, but this message shows up exactly because you're returning a string/undefined, instead of a function.

  • Custom User Avatar

    it calls the function inappropriately

    As far as I can tell, the only thing that's broken here is your solution. The description has an example of how it's supposed to work, so you can have a general idea about what to expect - if you don't know how to achieve this, how come it's the kata's fault?

  • Default User Avatar

    I slightly modified the description.

  • Custom User Avatar

    Is this meant to be the input, num?

    Yes. But only when there are many people with the same number or when it's not in the phone book. No idea why an alias was used there.

  • Custom User Avatar

    I guess unshift has to move all the elements one position and then you have a nested loop there. Not sure, but very likely.

  • Custom User Avatar

    Well that's the challenge, isn't it?

  • Default User Avatar

    Not sure what you mean exactly, but here's the rule you might've missed:

    • No whitespaces / underscore

    so cases 2 and 4 fail because they contains spaces or _

    "At least one character ("" is not valid)" => string is at least 1 character long (not empty string)

  • Custom User Avatar

    At least one character ("" is not valid) means empty string is not valid.

  • Custom User Avatar

    indexOf is a loop-alike method, so you're using nested loops there.