check out array.filter or if you want something ev...
# suitescript
c
check out array.filter or if you want something even fancier lodash has some methods exactly for this type of thing
r
array.filter is what i was planning on using. i'm tripped up on it.
b
for filter the first parameter is a function
the function has 3 parameters, the current element, the index, and the array itself
the function is supposed to return true if you want to keep the element
false if you dont want it
the return value of filter is an array of elements that had true returned
if you are implementing a uniqueness function, you need to keep track of which emails you have already added, and return false if you already processed that email
r
like so? i can normally get by with just elem and indexOf
works. thanks
unless someone wants to show me a better way
b
formal computer science says your solution is O(n^2)
r
ya, i can see that. lol keep looking i guess
c
its netsuite.. i'd take that runtime lol
b
if your array is small, it doesnt matter
r
can i get a hint? is it indexOf for ES5?
c
its most likely never going to matter w/ the data sets in netsuite
b
i was steering you towards using an object to keep track of which emails you added
that said, im with @creece, it doesnt matter unless you start hundreds of thousands of elements
r
of course. i shouldn't have cluttered up the array in the first place lol
b
tens of thousands might have measurable impact, but thats more rhino is slow
c
yeah even if you have an O(n) who knows how rhino does it
It would have to be an obscene amount of records to matter so it doesn't really.. if 10s of thousands probably wouldn't matter you'd need a ton before you'd see any NOTICEABLE slowdown
on paper, sure there's a difference but in real world for this its so tiny
r
this is a suitelet, folks
and i'm doing searches iteratively haha
a
Here's a much more compact method if you're able to use SS2.1:
Copy code
data.filter((el, i) => data.map(obj => obj.email).indexOf(el.email) === i);
r
I'm not, at the moment. 2.1 broke email logging for me on records when you specify a relatedRecord when sending an email. As far as I know it's an ongoing issue.
b
if you are concerned about performance, keep track of emails that have been seen already
if its not a concern, leave it as is, your implementation is fine
if you are paranoid, use lodash, or at least look at how lodash does it