728x90
function solution(arr, queries) {
let result = [...arr];
queries.map(indexes => {
const i1 = indexes[0];
const i2 = indexes[1];
result[i1] = arr[i2];
result[i2] = arr[i1];
arr = [...result];
})
return result;
}
์..
์ ๋ ์๋๊ฐ์ ๋ฐฉ๋ฒ์ด ์๊ฐ์ด ์๋ ๊น?
function solution(arr, queries) {
queries.forEach( ([a,b]) => {
[arr[a],arr[b]] = [arr[b],arr[a]];
})
return arr;
}
728x90
๋ฐ์ํ