Refactor of karnaugh.js