Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit be7108e

Browse filesBrowse files
authored
Update 27. Remove Element.js
add explanation to problem 27
1 parent b1d0308 commit be7108e
Copy full SHA for be7108e

File tree

Expand file treeCollapse file tree

1 file changed

+6
-1
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+6
-1
lines changed

‎21-30/27. Remove Element.js

Copy file name to clipboard
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
var removeElement = function(nums, val) {
2+
// we have to return number of elements not equal to val in nums
3+
// while removing all occurenece of val in place
24
let k = 0
5+
// run a for loop over nums
36
for(let i = 0; i < nums.length ;i++){
7+
// when nums[i] is not equal to val assign nums[k] with nums[i]
8+
// k is position(and counter) for value which are not equal to k
49
if(!(nums[i] == val)){
510
nums[k] = nums[i]
611
k++
712
}
813
}
914
return k
10-
};
15+
};

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.