Remove Element
Given an integer array nums and an integer val, remove all occurrences of val in-place. The order of the remaining elements can be changed. Return the number of elements in nums which are not equal to val. The first k elements of nums should hold the result (where k is the returned value).
Input: nums = [3,2,2,3], val = 3
Output: 2, nums = [2,2,_,_]
function removeElement(nums, val) {
let k = 0; // write index for elements != val
for (let i = 0; i < nums.length; i++) {
if (nums[i] !== val) {
nums[k] = nums[i];
k++;
}
}
return k;
}