Wrote my first algorithm in JS...