Last active
December 27, 2016 04:50
-
-
Save kenmori/23c5085e98712867018f7a419c9ee7b7 to your computer and use it in GitHub Desktop.
【JavaScript】2以上の配列の差分を新たな配列として返す方法(array-diff) How to return the difference between two sequences as a new array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const arr = [1, 2, 3, 4, 6] | |
| const arr2 = [1, 2, 3, 4, 5] | |
| const arr3 = [...arr, ...arr2] | |
| const a = [] | |
| for (let [i, e] of arr3.entries()) { | |
| if(!arr.includes(e)) a.push(e) | |
| if(!arr2.includes(e)) a.push(e) | |
| } | |
| console.log(a) | |
| //[6, 5] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment