I am trying to sort some words that i provide with another splitted words the input i give is
a = "excel|side|home|door"
b = "|"
c = "or|de|el"
and the code i am using is as
data.result = a.split(b)?.filter(x=>c.split(b).some(y => x.includes(y))).join(b);
that gives the output as excel|side|door
which is respective/order as ‘a’ input but i want it ti return b as a order of ‘a’ instead of returning excel|side|door
i want it to return as el|de|or
.
2
Answers
You can use
flatMap
to combinefilter
andmap
here. In addition, useArray#find
to get the actual matching element rather than just checking for existence.Sort by the index they are found in
a
: