Javascript in place solution
Only swap when necessary!\n\njavascript\nconst sortArrayByParity = (A) => {\n  for (let i = 0, j = -1, arrLen = A.length; i < arrLen; i++) {\n    if ((A[i] & 1)
**Only swap when necessary!**\n\n```javascript\nconst sortArrayByParity = (A) => {\n  for (let i = 0, j = -1, arrLen = A.length; i < arrLen; i++) {\n    if ((A[i] & 1) === 0 && j >= 0) { [A[i], A[j++]] = [A[j], A[i]]; }\n    else if (A[i] & 1) { j = j === -1 ? i : j; }\n  }\n  return A;\n};\n```
['JavaScript']