sentence는 하나의 빈칸으로 분리된 단어들의 목록입니다.
sentence는 마지막의 하나의 숫자를 더하고 섞여 있습니다.
예) "This is a sentence" => "is2 sentence4 This1 a3"
9개 이하의 단어로 이루어진 섞인 sentense s를 원본 sentence로 바꾸어 return해주세요.
Input: s = "is2 sentence4 This1 a3"
Output: "This is a sentence"
Explanation: Sort the words in s to their original positions "This1 is2 a3 sentence4", then remove the numbers.
var sortSentence = function(s) {
let array = [];
let split = s.split(" ")
for(i=0;i<split.length;i++) {
// 해당 단어의 마지막 숫자를 indexVal에 저장
// 예) sentence4 => indexVal = 4
let indexVal = split[i][split[i].length-1]
array[indexVal-1] = split[i].slice(0,split[i].length-1);
}
return array.join(" ");
}