I am stuck with this challenge, any help would be great.
'Create a function that takes both a string and an array of numbers as arguments. Reorder the letters in the string so that they are in the order indicated by the index numbers. Return the string "remixed". Examples
remix ("abcd", [0, 3, 1, 2]) ➞ "acdb" '
My attempt is
function remix(str, arr) { var arr2 = []; for (var i=0; i<str.length; i++){ arr2.splice(arr[i], 0, str[i]); } return arr2.join("");
}
This will solve some, but not all tests. EG. ("abcd", [0, 3, 1, 2]) = "acdb", but some are not. EG. "responsibility", [0, 6, 8, 11, 10, 7, 13, 5, 3, 2, 4, 12, 1, 9]) should be - "rtibliensyopis" my "rteislbpoyinsi"
source share