-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
63 lines (57 loc) · 1.29 KB
/
index.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
// Code your solution here!
function printString(myString) {
console.log(myString[0]);
if (myString.length > 1) {
let mySubString = myString.substring(1, myString.length);
printString(mySubString);
} else {
return true;
}
}
function reverseString(myString) {
console.log(myString[0]);
if (myString.length === 1) {
return myString
} else {
return reverseString(myString.substring(1)) + myString[0]
}
}
function isPalindrome(myString) {
if (myString.length === 1) {
return true
} else {
if(myString[myString.length - 1] === myString[0]) {
return isPalindrome(myString.substring(1, myString.length - 1))
} else {
return false
}
}
}
function addUpTo(myArray, index) {
if (index === 0) {
return myArray[0]
} else {
return myArray[index] + addUpTo(myArray, index - 1)
}
}
function maxOf(myArray) {
if( myArray.length > 1 ) {
if( myArray[0] > myArray[1] ) {
myArray.splice(0,2, myArray[0])
} else {
myArray.splice(0,2, myArray[1])
}
return maxOf(myArray)
}
return myArray[0]
}
function includesNumber(myArray, num) {
if (myArray.length === 0) {
return false
} else if (myArray[0] === num) {
return true
} else {
myArray.shift()
return includesNumber(myArray, num)
}
}