From 1f6915bd01c9419133f48e29c55dedd25a697899 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Mon, 23 Jun 2014 13:42:32 +1000 Subject: [PATCH] index: avoid overwrite, use words variable --- index.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index c0ebdbc..e9f25d1 100644 --- a/index.js +++ b/index.js @@ -37,20 +37,19 @@ BIP39.prototype.generateMnemonic = function(strength) { } BIP39.prototype.validate = function(mnemonic) { - mnemonic = mnemonic.split(' ') + var words = mnemonic.split(' ') - if (mnemonic.length % 3 !== 0) return false + if (words.length % 3 !== 0) return false var wordlist = this.wordlist - - var belongToList = mnemonic.every(function(word) { + var belongToList = words.every(function(word) { return wordlist.indexOf(word) > -1 }) if (!belongToList) return false - var bits = mnemonic.map(function(m) { - var id = wordlist.indexOf(m) + var bits = words.map(function(word) { + var id = wordlist.indexOf(word) return lpad(id.toString(2), '0', 11) }).join('')