I have an array of similar kind of strings like the list of landmarks :
["AB Street", "A B Street", "AB Street XE", "AB Street X", "AB Street(XE)"]
Each of these represent a single landmark "AB Street".
I have tried different approaches, found a way for removing extra spaces and special characters but not able to figure out how to cut short the extraneous entries with extended names which anyways lead to same string.
Code snippet for removing spaces and special characters :
var landmarks = ["AB Street", "A B Street", "AB Street XE", "AB Street X", "AB Street(XE)"];
var formattedLandmarks = [];
landmarks.sort();
landmarks.forEach(function(location) {
var key = location && location.toLowerCase();
key = key.replace(/[.\/-]*/g, "");
key = key.replace(/\(.*\)/i, "");
key = key.replace(/[0-9, _-]*$/, "");
key = key.replace(/[ \t]+/g, " ");
key = key.toString().trim();
key = key.charAt(0).toUpperCase() + key.slice(1);
formattedLandmarks.push(key);
});
console.log(formattedLandmarks);
I expect the algorithm to return output as array with only one entry :
["AB Street"]
It will be really great if someone can help out with the best possible approach and algorithm to achieve the expected output, be it through RegExp or some other way.
Any help is appreciable.
[ "ABStreet", "AB Street XQ", "AB Street XEA", "AB Street(XE)"]- how should look the expected result for it?similar_text()which has apparently been ported to JS here. Not sure if this is the right algorithm for your needs, though.