-
Notifications
You must be signed in to change notification settings - Fork 0
/
without.js
82 lines (61 loc) · 1.72 KB
/
without.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* function checkArrays( arrA, arrB ){
//check if lengths are different
if(arrA.length !== arrB.length) return false;
//slice so we do not effect the orginal
//sort makes sure they are in order
var cA = arrA.slice();
var cB = arrB.slice();
for(var i=0;i<cA.length;i++){
if(cA[i]!==cB[i]) return false;
}
return true;
let eqArrays = function(arr1,arr2){
// if length is not equal
let a=arr1.length
let b=arr2.length
if(a!==b){
console.log("the arrays are not equal")
}
else{
// comapring each element of array
for(var i=0;i<arr1.length;i++)
if(arr1[i]!=arr2[i])
return "False"
else
return "True"
}
}
let assertArraysEqual = function(arr1,arr2){
var flag = checkArrays(arr1, arr2)
console.log(flag)
if(flag == true){
console.log('Assertion Passed:' + arr1 + ' === ' + arr2);
}else{
console.log('Assertion Failed: ' + arr1 + ' !== ' + arr2);
}
} */
/* assertArraysEqual([1, 2, 3], [1, 2, 3])
assertArraysEqual([3, 2, 1], [1, 2, 3])
assertArraysEqual(["1", "2", "3"], ["1", "2", "3"])
assertArraysEqual(["1", "2", "3"], ["1", "2", 4]) */
function without (a1, a2) {
var a = [], diff = [];
for (var i = 0; i < a1.length; i++) {
a[a1[i]] = true;
}
for (var i = 0; i < a2.length; i++) {
if (a[a2[i]]) {
delete a[a2[i]];
} else {
a[a2[i]] = true;
}
}
for (var k in a) {
diff.push(k);
}
return diff;
}
console.log(without(['a', 'b'], ['a', 'b', 'c', 'd']));
console.log(without("abcd", "abcde"));
console.log(without("zxc", "zxc"));
console.log(without(["hello", "world", "lighthouse"],["Lighthouse"]))