-
Notifications
You must be signed in to change notification settings - Fork 0
/
EXAMPLES
62 lines (46 loc) · 1.3 KB
/
EXAMPLES
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
EXAMPLES
- palindrome (FCC Javscript)
function palindrome(str) {
var newStr = str.toLowerCase().replace(/[^A-Za-z0-9]/g,'');
var len = newStr.length;
for(var i=0; i<len/2; ++i)
if(newStr[i]!=newStr[len-i-1])
return false;
return true;
}
- Longest word of the sentence (FCC JS):
function findLongestWord(str) {
var chkStr = str.split(' ');
var maxLen = 0;
for(var i =0; i<chkStr.length; ++i)
if(chkStr[i].length>maxLen)
maxLen = chkStr[i].length;
return maxLen;
}
- function confirmEnding(str, target) {
if(str.substr(-target.length)==target)
return true;
return false;
}
- Occurrence of str (FCC):
function mutation(arr) {
var one=arr[0].toLowerCase().split('');
var two=arr[1].toLowerCase().split('');
for(var i=0; i<two.length; ++i){
if(one.indexOf(two[i]) < 0)
return false;
}
return true;
}
- Destroy the mentioned elements:
function destroyer(arr) {
var args = Array.from(arguments);
return arr.filter(function(elm){
return !(args.indexOf(elm,1)+1); // indexOf returns -1 if not found
});
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
- Fade out elements and fadein stuff
$("#container").fadeOut(function() {
$(this).text("World").fadeIn();
});