I want to replace the last word of x with y if y includes the last word of x. How can I manage that?
let x ='jaguar lion tiger panda'
let y = 'pandas'
expected result:
'jaguar lion tiger pandas'
if
y = 'cat'
Expected result:
'jaguar lion tiger panda cat'
Code I've tried:
console.log(response)
let before = this.text.split(' ')
console.log(before)
console.log(before.length)
let a = before.slice(before.length-1)
console.log(a)
if (response.data.text[0].includes(a)) {
let x = (before.slice(0, before.length-1))
let y = x.replace(',', ' ')
this.preResult = y.push(response.data.text[0])
} else {
this.preResult.push(this.text + ' ' + response.data.text[0])