Discrepancy computation in O(n).
Discrepancy computation in O(n).

This patch ports https://codereview.chromium.org/1409143006/ to JS.

Review URL: https://codereview.chromium.org/1883143002

catapult-project/catapult-csm,benschmaus/catapult,sahiljain/catapult,sahiljain/catapult,catapult-project/catapult,catapult-project/catapult-csm,benschmaus/catapult,benschmaus/catapult,catapult-project/catapult,catapult-project/catapult,catapult-project/catapult-csm,sahiljain/catapult,benschmaus/catapult,sahiljain/catapult,sahiljain/catapult,catapult-project/catapult,catapult-project/catapult,catapult-project/catapult-csm,benschmaus/catapult,catapult-project/catapult-csm,catapult-project/catapult-csm,catapult-project/catapult,catapult-project/catapult,benschmaus/catapult,sahiljain/catapult,catapult-project/catapult-csm,benschmaus/catapult