Skip to content

Commit 6a3efc4

Browse files
Solved more problems
1 parent 04b9015 commit 6a3efc4

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1-
function reverseString() {}
1+
function reverseString(str) {
2+
let len = str.length - 1
3+
let result = ''
4+
for(let i=len; i >=0; i-- ) {
5+
result += str[i]
6+
}
7+
8+
return result
9+
}
210

311
module.exports = reverseString;
Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1-
function isPalindrome() {}
1+
function isPalindrome(str) {
2+
3+
str = str.toLowerCase()
4+
str = str.replace(/[^a-z0-9]/g,"")
5+
let [left,right ]= [0, str.length -1]
6+
7+
let result = true
8+
while(left<=right) {
9+
if(str[left]!=str[right]) {
10+
result = false
11+
break
12+
} else {
13+
left++
14+
right--
15+
}
16+
}
17+
18+
return result
19+
}
220

321
module.exports = isPalindrome;

0 commit comments

Comments
 (0)