discovering patterns in javascript