-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathb.js
More file actions
24 lines (24 loc) · 672 Bytes
/
b.js
File metadata and controls
24 lines (24 loc) · 672 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const myIsPal2 = function (str, modify = [null, null]) {
let reverseStr = str.split('').reverse().join('')
console.log('reverseStr', reverseStr)
console.log(str, reverseStr)
if (reverseStr === str) {
return true
} else {
// try to modify
const [what, value] = modify
if ( (what !== null) && ( value !== null) )
{
console.log('----------1', [what, value])
const reg = new RegExp(what, "g")
const str2 = str.replace(reg, value)
const reverseStr2 = str2.split('').reverse().join('')
if (reverseStr2 === str2)
{
return true
}
}
}
return false
}
console.log(myIsPal2('abccbx', ['x', 'a']))