문제 링크 : Sort Array By Parity
/**
* @param {number[]} nums
* @return {number[]}
*/
var sortArrayByParity = function(nums) {
let evenArr = []
let oddArr = []
nums.forEach(e => e%2 ? oddArr.push(e) : evenArr.push(e))
return [...evenArr, ...oddArr]
};
/**
* @param {number[]} nums
* @return {number[]}
*/
var sortArrayByParity = function(nums) {
let currPtr = -1;
let temp;
for(let i=0;i<nums.length;i++) {
if (nums[i]%2 === 0) {
currPtr++;
temp = nums[currPtr];
nums[currPtr] = nums[i];
nums[i] = temp;
}
}
return nums;
};