Ad
  • Custom User Avatar

    Think I have some adviсes for your code. Firstly you receive an infinite loop because when the space are added to position whith index i+1 (btw you don't need use construction "array.indexOf(array[i + 1])", just "i+1") in the next round of your loop you will examine element of array which contents this just added space. Space satisfies condition of your if, your script will add enother space to next position and examine it in the next round. You will never come to else branch.
    You must move on to position after just added space in next round. Add "i=i+2;" after "array.splice...;" (+2 because you don't need to examine space and next standing uppercase letter). And remove your else branch. Another thing: in condition of your loop you must handle elements only up to "i < array.length-1". The last element will be examinated in the penultimate round.

  • Custom User Avatar

    I'm very impressed by this solution, but still try to understand it completely))

  • Custom User Avatar

    In descritption we see:
    "The input data consist of an array which contains five names, and single integer n.
    (1 ≤ n ≤ 1 000 000 000)."
    But in output/examples we must receive "Leonard" for n == 7 230 702 951.
    How can it be possible?