Files
Exponent GitHub Bot e3f6a67ce5 Initial commit
fbshipit-source-id: 04f171ad7fc354fbc437cd07abdee445323d9a0f
2018-07-17 18:51:11 +00:00

7 lines
170 B
JavaScript

export const swap = (a, x, y) => {
if (a.length === 1) return a;
const result = [...a];
result.splice(y, 1, result.splice(x, 1, result[y])[0]);
return result;
};