all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
16
Task/Symmetric-difference/JavaScript/symmetric-difference.js
Normal file
16
Task/Symmetric-difference/JavaScript/symmetric-difference.js
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
// in A but not in B
|
||||
function relative_complement(A, B) {
|
||||
return A.filter(function(elem) {return B.indexOf(elem) == -1});
|
||||
}
|
||||
|
||||
// in A or in B but not in both
|
||||
function symmetric_difference(A,B) {
|
||||
return relative_complement(A,B).concat(relative_complement(B,A));
|
||||
}
|
||||
|
||||
var a = ["John", "Serena", "Bob", "Mary", "Serena"].unique();
|
||||
var b = ["Jim", "Mary", "John", "Jim", "Bob"].unique();
|
||||
|
||||
print(a);
|
||||
print(b);
|
||||
print(symmetric_difference(a,b));
|
||||
Loading…
Add table
Add a link
Reference in a new issue