I have a list of strings and nulls. Now I want to check if all strings in the list are the same and nulls should be ignored. So for instance
[null, "a", "a", null, "a"]
should evaluate totrue
, because all strings are equal[null, "a", "a", null, "b"]
should evaluate tofalse
, because there is "b" and "a"
There are other questions on SO that are concerned with finding duplicates or equal values, but none of them seem to consider null
values.
I already thought about implementing this with
- a loop where I would save the first string and then compare to it in the later iterations
- a
filter
followed byevery
However I was wondering if there is a better more intuitive way to do this.