You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create a function that takes two or more arrays and returns an array of the symmetric difference (△ or ⊕) of the provided arrays.
4
+
5
+
Given two sets (for example set A = {1, 2, 3} and set B = {2, 3, 4}), the mathematical term "symmetric difference" of two sets is the set of elements which are in either of the two sets, but not in both (A △ B = C = {1, 4}). For every additional symmetric difference you take (say on a set D = {2, 3}), you should get the set with elements which are in either of the two the sets but not both (C △ D = {1, 4} △ {2, 3} = {1, 2, 3, 4}). The resulting array must contain only unique values (no duplicates).
Return the number of total permutations of the provided string that don't have repeated consecutive letters. Assume that all characters in the provided string are each unique.
4
+
5
+
For example, aab should return 2 because it has 6 total permutations (aab, aab, aba, aba, baa, baa), but only 2 of them (aba and aba) don't have the same letter (in this case a) repeating.
6
+
*/
7
+
8
+
functionpermAlone(str){
9
+
letarr=str.split("");
10
+
11
+
letresult=[];
12
+
functionpermute(arr,l,r){
13
+
if(l==r){
14
+
result.push(arr.join(""));
15
+
}
16
+
else{
17
+
for(leti=l;i<=r;i++){
18
+
[arr[i],arr[l]]=[arr[l],arr[i]];//swap position
19
+
permute(arr,l+1,r);//recursive call
20
+
21
+
[arr[i],arr[l]]=[arr[l],arr[i]];//swap back
22
+
}
23
+
}
24
+
};
25
+
permute(arr,0,arr.length-1);
26
+
27
+
letregex=/(.)\1+/;//matches the same text as most recently matched by the 1st capturing group
0 commit comments