Skip to content

Commit 0054647

Browse files
authored
Create 905-sort-array-by-parity.js
1 parent c308ac0 commit 0054647

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

905-sort-array-by-parity.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @param {number[]} A
3+
* @return {number[]}
4+
*/
5+
const sortArrayByParity = function(A) {
6+
for(let i = 0, len = A.length; i < len;) {
7+
if(A[i] % 2 !== 0) {
8+
A.push(A[i])
9+
A.splice(i, 1)
10+
len--
11+
} else {
12+
i++
13+
}
14+
}
15+
return A
16+
};

0 commit comments

Comments
 (0)