-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.js
84 lines (67 loc) · 1.7 KB
/
example.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
81
82
83
84
function anagramTest(a, b){
let arrayA = Array.from(a).sort();
let arrayB = Array.from(b).sort();
if (arrayA.length != arrayB.length){
return false;
}
for(let i=0; i < arrayA.length; i++){
if(arrayA[i] != arrayB[i]){
return false;
}
}
return true;
}
function palindromeTest(a){
let A = a.toLowerCase();
let B = Array.from(a.toLowerCase()).reverse().join("");
console.log(B);
if (A === B){
return true;
}
return false;
}
function middleReturn(elementList){
let i = Math.floor(elementList.length / 2);
return [elementList[i], i];
}
function setReturn(a){
let A = a.toLowerCase();
let B = new Set();
A.split("").forEach(letter => B.add(letter));
return B;
}
function numCount(numArray){
let counter = {};
for(let i = 0; i < numArray.length; i++){
if(counter[numArray[i]]){
counter[numArray[i]]++;
}
else{
counter[numArray[i]] = 1;
}
}
return counter;
}
function reverseWords(phrase){
let blaze = phrase.split(" ");
return blaze.reverse().join(" ");
}
function commonLetters(a,b){
let setA = new Set(Array.from(a));
let setB = new Set(Array.from(b));
let C = [];
console.log(setA);
setA.forEach((entry)=>{
if (setB.has(entry)){
C.push(entry);
}
});
return C;
}
console.log(commonLetters("aaabbscs","abczc"));
console.log(reverseWords("banana boy"));
console.log(numCount([1,2,3,2,2,2,3,4,5]))
console.log(setReturn("aaahdhhhshhaaahhsdssd"))
console.log(palindromeTest("girafarig"))
console.log(anagramTest("dog","god"));
console.log(anagramTest("dog","cat"));