I have two file path as strings:
const filePath = "reports/cucumber/7/cucumber/sample/json/login.json"
const reportFolder = "reports/cucumber/7/cucumber/sample"
I need to compare these two and then get the output as
/json/login.json
How can I do this?
CodePudding user response:
You could also use String.replace()
to get the difference:
const filePath = "reports/cucumber/7/cucumber/sample/json/login.json"
const reportFolder = "reports/cucumber/7/cucumber/sample"
const diff = filePath.replace(reportFolder, '');
console.log('Diff:', diff)
CodePudding user response:
const filePath = "reports/cucumber/7/cucumber/sample/json/login.json"
const reportFolder = "reports/cucumber/7/cucumber/sample"
const diff = (diffMe, diffBy) => diffMe.split(diffBy).join('')
const C = diff(filePath, reportFolder)
console.log(C)