Created
May 28, 2020 17:13
-
-
Save MinSomai/5fc088b5974e6822c3f6e1dffaa2efda to your computer and use it in GitHub Desktop.
Intermediate Algorithm Scripting: Diff Two Arrays
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
| function diffArray(arr1, arr2) { | |
| let first = checkOnce(arr1, arr2); | |
| let second = checkOnce(arr2, arr1); | |
| return first.concat(second); | |
| } | |
| function checkOnce(arr1, arr2){ | |
| let unique = []; | |
| arr1.every(item=>{ | |
| if(!arr2.some(innerItem=> { | |
| if(innerItem == item) | |
| return true; | |
| else | |
| return false; | |
| })){ | |
| unique.push(item); | |
| } | |
| return true; | |
| }); | |
| return unique; | |
| } | |
| diffArray(["andesite", "grass", "dirt", "pink wool", "dead shrub"], ["diorite", "andesite", "grass", "dirt", "dead shrub"]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment