Marina Mosti is a full-stack web developer with over 14 years of experience in the field. She enjoys mentoring other women on JavaScript and her favorite framework, Vue.
I feel it's important to distinguish that the OP-s solution loops over the whole array twice. I know there are times to make a trade-off between performance and readability, but I don't feel this needs to be one of those times :)
Without getting into cryptic one-liners, there's a pretty straight forward linear time solution as well.
wow crazy matt
thanks for this
Hey Matt, nice solution! Yeah, all ways leads to Rome :)
Well... yes and no.
I feel it's important to distinguish that the OP-s solution loops over the whole array twice. I know there are times to make a trade-off between performance and readability, but I don't feel this needs to be one of those times :)
Great answer, thank you Matt!