Blog | December 13th, 2012

As a programmer, I can’t tell you how many times the answer to a problem has had overwhelmingly more to do with how I’m looking at things than actual difficulty. Turn just a little bit, and you’ll usually find that your insistence on seeing the world a certain way was all that stood between you and simple, elegant progress.

I recently had two arrays and wanted to find the differences between them. Not just the things that existed in the first but not the second, or vice versa, but both. I searched high and low for an easy answer, though nothing really clicked with me. Every solution involved two trips: one to find the items in the first but not the second, and another to find what was in the second but not the first. I knew there was a better way.

Sure enough, by removing the duplicates rather than sequestering the differences I was able to get the results I wanted from both arrays in one quick sweep. An easy, elegant answer to a problem defined more by my insistence on seeing white on black instead of black on white. Sometimes you just have to think in opposites.