Maybe it would be to cache this, to avoid doing the O(n) operation twice.