Title: Writing function Array_diff (A, b), passing in two arrays, a, a, a, the value of the array A is all removed, the duplicate is removed, and the new array is removed.
JavaScript] View plain Copy
- <span style="Font-family:microsoft yahei;font-size:14px;" >function Array_diff (A, b) {
- return A.filter (e =!b.includes (e));
- }</span>
Ex
Array_diff ([1,2,3,3,4],[3]) = [1, 2, 4]
1. Filter ()
The filter () method creates a new array of elements in the new array by examining all the elements in the specified array that meet the criteria.
Note: Filter () does not detect empty arrays.
Note: Filter () does not change the original array.
Filter: Select elements in the original array that match the criteria to form a new array
var subarr=arr.filter (function (Val,i,arr) {
return condition; All elements that return true are copied to the new array
})
2, includes ()
includes()
method is used to determine whether an array contains a specified value, and if so, returns True or false, as appropriate.
let a = [123;a. Includes (2//true a. Includes (4//false
JS Note--filter,includes