-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray.diff-kyu5.js
More file actions
18 lines (12 loc) · 844 Bytes
/
Array.diff-kyu5.js
File metadata and controls
18 lines (12 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
DESCRIPTION:
// Your goal in this kata is to implement a difference function, which subtracts one list from another and returns the result.
// It should remove all values from list a, which are present in list b keeping their order.
// arrayDiff([1,2],[1]) == [2]
// If a value is present in b, all of its occurrences must be removed from the other:
// arrayDiff([1,2,2,2,3],[2]) == [1,3]
function arrayDiff(a, b) {
return a.filter(val => !b.includes(val));
}
// We use filter in this case. filter, unlike foreach, will return an array based on what passed the parameters, similar to map.
// we take the array of a and use .filter() and create an arrow function with val being the parameter if each value of a.
// With this function return an array that does not include the value of our a value in b. written like !b.