I’m writing a function to compare to music artist strings, but come in different formats. Would would be a suggested approach?
Example Strings (Both are from the same song, just formatted differently):
// Eli & Fur & Brothertiger // Brothertiger, Eli & Fur
What would be the suggested approach to compare these strings that I could match both artists
"Eli & Fur & Brothertiger" and
"Brothertiger, Eli & Fur"?
songTitle, then for loop over each string
songTitle, but then that gets messed with with an artist name
such as "Eli & Fur"with a
I’d split by either
& or a comma.
const toArr = str => str.split(/ *(?:&|,) */); console.log(toArr('Eli & Fur & Brothertiger')); console.log(toArr('Brothertiger, Eli & Fur'));
Then check that the lengths are the same and that every element of one array exists in the other.
Answered By – CertainPerformance
Answer Checked By – Senaida (BugsFixing Volunteer)