Diff Two Arrays code example
Example 1: bash test boolean
the_world_is_flat=true
if [ "$the_world_is_flat" = true ] ; then
echo 'Be careful not to fall off!'
fi
Example 2: array differenc javascript
let difference = arr1.filter(x => !arr2.includes(x));
Example 3: diff two arrays javascript
function diffArray(arr1, arr2) {
return arr1
.concat(arr2)
.filter(item => !arr1.includes(item) || !arr2.includes(item));
}
Example 4: boolean constants in bash
true, false
Example 5: Diff Two Arrays
const diffArray = (arr1, arr2) => {
const diffArray = []
const uniqueArr = [...new Set([...arr1, ...arr2])];
uniqueArr.forEach(elem => {
if(!arr1.includes(elem) || !arr2.includes(elem))
diffArray.push(elem)
})
return diffArray
}
diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);