例如如何从字符串中删除重复项
const string = 'PandoraPandora'; to --> Pandora
OR
const string = 'pandorapandora'; to --> pandora
注意:字符串中没有空格。
答案 0 :(得分:0)
您在这里:
const str = 'pandorapandora'
const midIndex = Math.floor(str.length/2)
const firstHalf = str.slice(0,midIndex)
const secondHalf = str.slice(midIndex)
const dup = firstHalf == secondHalf ? firstHalf : str
console.log(dup)