I am currently on the codewars site trying to improve my JavaScript along with other things. This question will give an input like this
'is2 Thi1s T4est 3a' and expect an output like this 'Thi1s is2 3a T4est'
I am having trouble indexing the string. It seems odd as I've done it before in Python but even trying this in Python I don't get the proper output.
Here is my code, before it was giving me at least an array of the numbers but now I just get [ Array(4) ].
I know that the proper output should be a string but once I get it all in an array I plan to just tempSentence.join(" ") the array and return it. Sorry that is kind of messy but I kept trying different things:
function order(words){
let hasNumber = /\d/;
let newSentence = words.split(" ")
let tempSentence = words.split(" ")
for (let i = 0; i < newSentence.length; i++){
for (let j = 0; j < newSentence[i].length; j++){
if (hasNumber.test(newSentence[i][j])){
tempSentence[words[i][j]-1] = newSentence[i]
}
}
}
return tempSentence
}