Javascript djb redo implementation