Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

Commonmark migration
Source Link

You can try something like this:

###Logic

Logic

  • Sort the array in ascending order
  • Set initial value to be blank
  • Loop over and check if current value has previous. If not, then push it in array.

Note: You are comparing parsed values, so you should sort based on these parsed values only.

var array = ["AB Street", "A B Street", "AB Street XE", "AB Street X", "AB Street(XE)"];
var regex = /[^a-z]/gi;
var final = [];
array.sort(function(item1, item2){
 var _a = item1.replace(regex,"");
 var _b = item2.replace(regex,"");
 return _a > _b? 1: _a < _b ? -1: 0;
}).reduce(function(currentItem, nextItem) {
 var _p = currentItem.replace(regex, "");
 var _c = nextItem.replace(regex, "");
 if (_c.indexOf(_p)<0 || !currentItem) {
 final.push(nextItem);
 }
 return nextItem;
}, "")
console.log(final)

###Reference

Reference

You can try something like this:

###Logic

  • Sort the array in ascending order
  • Set initial value to be blank
  • Loop over and check if current value has previous. If not, then push it in array.

Note: You are comparing parsed values, so you should sort based on these parsed values only.

var array = ["AB Street", "A B Street", "AB Street XE", "AB Street X", "AB Street(XE)"];
var regex = /[^a-z]/gi;
var final = [];
array.sort(function(item1, item2){
 var _a = item1.replace(regex,"");
 var _b = item2.replace(regex,"");
 return _a > _b? 1: _a < _b ? -1: 0;
}).reduce(function(currentItem, nextItem) {
 var _p = currentItem.replace(regex, "");
 var _c = nextItem.replace(regex, "");
 if (_c.indexOf(_p)<0 || !currentItem) {
 final.push(nextItem);
 }
 return nextItem;
}, "")
console.log(final)

###Reference

You can try something like this:

Logic

  • Sort the array in ascending order
  • Set initial value to be blank
  • Loop over and check if current value has previous. If not, then push it in array.

Note: You are comparing parsed values, so you should sort based on these parsed values only.

var array = ["AB Street", "A B Street", "AB Street XE", "AB Street X", "AB Street(XE)"];
var regex = /[^a-z]/gi;
var final = [];
array.sort(function(item1, item2){
 var _a = item1.replace(regex,"");
 var _b = item2.replace(regex,"");
 return _a > _b? 1: _a < _b ? -1: 0;
}).reduce(function(currentItem, nextItem) {
 var _p = currentItem.replace(regex, "");
 var _c = nextItem.replace(regex, "");
 if (_c.indexOf(_p)<0 || !currentItem) {
 final.push(nextItem);
 }
 return nextItem;
}, "")
console.log(final)

Reference

added 355 characters in body
Source Link
Rajesh Dixit
  • 25.1k
  • 5
  • 52
  • 86

You can try something like this:

###Logic

  • Sort the array in ascending order
  • Set initial value to be blank
  • Loop over and check if current value has previous. If not, then push it in array.

Note: You are comparing parsed values, so you should sort based on these parsed values only.

var aarray = ["AB Street", "A B Street", "AB Street XE", "AB Street X", "AB Street(XE)"];
var rregex = /[^a-z]/gi;
var ffinal = [];
aarray.sort(function(aitem1,b item2){
 var _a = aitem1.replace(rregex,"");
 var _b = bitem2.replace(rregex,"");
 return _a > _b? 1: _a < _b ? -1: 0;
}).reduce(function(pcurrentItem, cnextItem) {
 var _p = pcurrentItem.replace(rregex, "");
 var _c = cnextItem.replace(rregex, "");
 if (_c.indexOf(_p)<0 || !pcurrentItem) {
 ffinal.push(cnextItem);
 }
 return c;nextItem;
}, "")
console.log(ffinal)

###Reference

You can try something like this:

###Logic

  • Sort the array in ascending order
  • Set initial value to be blank
  • Loop over and check if current value has previous. If not, then push it in array.

Note: You are comparing parsed values, so you should sort based on these parsed values only.

var a = ["AB Street", "A B Street", "AB Street XE", "AB Street X", "AB Street(XE)"];
var r = /[^a-z]/gi;
var f = [];
a.sort(function(a,b){
 var _a = a.replace(r,"");
 var _b = b.replace(r,"");
 return _a > _b? 1: _a < _b ? -1: 0;
}).reduce(function(p, c) {
 var _p = p.replace(r, "");
 var _c = c.replace(r, "");
 if (_c.indexOf(_p)<0 || !p) {
 f.push(c);
 }
 return c;
}, "")
console.log(f)

You can try something like this:

###Logic

  • Sort the array in ascending order
  • Set initial value to be blank
  • Loop over and check if current value has previous. If not, then push it in array.

Note: You are comparing parsed values, so you should sort based on these parsed values only.

var array = ["AB Street", "A B Street", "AB Street XE", "AB Street X", "AB Street(XE)"];
var regex = /[^a-z]/gi;
var final = [];
array.sort(function(item1, item2){
 var _a = item1.replace(regex,"");
 var _b = item2.replace(regex,"");
 return _a > _b? 1: _a < _b ? -1: 0;
}).reduce(function(currentItem, nextItem) {
 var _p = currentItem.replace(regex, "");
 var _c = nextItem.replace(regex, "");
 if (_c.indexOf(_p)<0 || !currentItem) {
 final.push(nextItem);
 }
 return nextItem;
}, "")
console.log(final)

###Reference

Source Link
Rajesh Dixit
  • 25.1k
  • 5
  • 52
  • 86

You can try something like this:

###Logic

  • Sort the array in ascending order
  • Set initial value to be blank
  • Loop over and check if current value has previous. If not, then push it in array.

Note: You are comparing parsed values, so you should sort based on these parsed values only.

var a = ["AB Street", "A B Street", "AB Street XE", "AB Street X", "AB Street(XE)"];
var r = /[^a-z]/gi;
var f = [];
a.sort(function(a,b){
 var _a = a.replace(r,"");
 var _b = b.replace(r,"");
 return _a > _b? 1: _a < _b ? -1: 0;
}).reduce(function(p, c) {
 var _p = p.replace(r, "");
 var _c = c.replace(r, "");
 if (_c.indexOf(_p)<0 || !p) {
 f.push(c);
 }
 return c;
}, "")
console.log(f)

lang-js

AltStyle によって変換されたページ (->オリジナル) /