How to remove duplicate from string for example
const string = 'PandoraPandora'; to --> Pandora
OR
const string = 'pandorapandora'; to --> pandora
Note: string doesn't have spaces.
How to remove duplicate from string for example
const string = 'PandoraPandora'; to --> Pandora
OR
const string = 'pandorapandora'; to --> pandora
Note: string doesn't have spaces.
Here you go:
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)