Forum Discussion
The expression language is a subset of JavaScript, so you can usually start by looking for JavaScript-based solutions.
In this case, take a look at this post:
The first answer has the simplest solution. The only change you have to make is to convert the callback function to use the arrow-function syntax, like so:
$arr.filter((item, pos, a) => a.indexOf(item) == pos)
Thank you. That was helpful :+1:
- robin9 years agoFormer Employee
Thanks @tstack! For anyone wondering what this looks like in the Designer::
Pipeline .slp file: 20170404_mapper-distinct-elements_2017_04_04.slp (3.0 KB)
- Anjali5 years agoNew Contributor
Can you please explain how this filter function is working? what is item , pos and a here and how there are related to each other and functioning?
- cjhoward185 years agoEmployee
Hi @Anjali
item
is the current item it is iterating over in the array,pos
is the position in the array for this item anda
is the array itself.The expression to remove duplicates is using the
indexOf()
to collect a single instance of each unique element in thefilter()
method sinceindexOf()
returns the first found index for each unique value each time.