so I looked at multiple sources including Finding All Combinations of JavaScript array values and https://codereview.stackexchange.com/questions/52119/calculate-all-possible-combinations-of-an-array-of-arrays-or-strings and am still coming up with a blank.
I am splitting the string "35 w 35 ave" into an array on " "
which I then compare to an arrays for values. Here is the object:
var addressObject = {
ave : ["av", "aven", "avenu", "avenue", "avn", "avnue"],
w : ["west", "wst", "w"]
};
I add this to var address = txtNode.val().split(' ');
which returns the array ['35','w','35','ave']
and then I take the array and put it through a nested forEach loop like so:
address.forEach( function(addressElement, indexOfAddressElement) {
var abbreviationMatch = addressObject.hasOwnProperty(addressElement);
if (abbreviationMatch) {
function addSentenceVariationsToAddressLists(arrayToLookAt) {
arrayToLookAt.forEach(function (anItem, a) {
var y = address.splice(indexOfAddressElement, 1, anItem);
addressLists.push(address.join(" "));
})
}
var elementsFromArray = addressObject[addressElement];
addSentenceVariationsToAddressLists(elementsFromArray);
}
});
console.log(addressLists);
This returns ["35 west 35 ave", "35 wst 35 ave", "35 w 35 ave", "35 w 35 av", "35 w 35 aven", "35 w 35 avenu", "35 w 35 avenue", "35 w 35 avn", "35 w 35 avnue"]
My question is: how do I return all of the variations of "ave"
with "wst"
and "west"
instead of just "w"
including the original value of the address
array?