I have created this function, with some assistance in this community and I would like to know if my if
statements could be shortened or improved as I am still new to JS and refining this function could open me to new knowledge.
Please see the code below:
let jo = [1,2,3,5,6]
let ji = [1,2,3,5,4]
const checker = (arr1, arr2) => {
return arr1.every(num => arr2.includes(num)) == false &&
arr2.every(num => arr1.includes(num)) == false ?
Array.from(new Set(arr1.filter(x => !new Set(arr2).has(x))))
.concat(Array.from(new Set(arr2.filter(x => !new Set(arr1).has(x))))) :
arr1.every(num => arr2.includes(num)) == false?
Array.from(new Set(arr1.filter(x => !new Set(arr2).has(x)))) :
arr2.every(num => arr1.includes(num)) == false ?
Array.from(new Set(arr2.filter(x => !new Set(arr1).has(x)))) :
"no discrepancies"
}
console.log(checker(jo, ji));