From 26b1617edff73353d5c4aa0fdeff2e196e7280ca Mon Sep 17 00:00:00 2001 From: wioniqle-q <69215407+wioniqle-q@users.noreply.github.com> Date: Mon, 15 Nov 2021 14:54:33 +0300 Subject: [PATCH] Update phonetic.js --- lib/key_generators/phonetic.js | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/lib/key_generators/phonetic.js b/lib/key_generators/phonetic.js index f281f6b..1b50780 100644 --- a/lib/key_generators/phonetic.js +++ b/lib/key_generators/phonetic.js @@ -1,27 +1,23 @@ // Draws inspiration from pwgen and http://tools.arantius.com/password - -const randOf = (collection) => { - return () => { - return collection[Math.floor(Math.random() * collection.length)]; - }; -}; - // Helper methods to get an random vowel or consonant -const randVowel = randOf('aeiou'); -const randConsonant = randOf('bcdfghjklmnpqrstvwxyz'); +const randOf = (collection) => { + return () => { + return collection[Math.floor(Math.random() * collection.length)]; + }; +}, randVowel = randOf('aeiou'), randConsonant = randOf('bcdfghjklmnpqrstvwxyz'); module.exports = class PhoneticKeyGenerator { - // Generate a phonetic key of alternating consonant & vowel - createKey(keyLength) { - let text = ''; - const start = Math.round(Math.random()); + // Generate a phonetic key of alternating consonant & vowel + createKey(keyLength) { + let text = ''; + const start = Math.round(Math.random()); - for (let i = 0; i < keyLength; i++) { - text += (i % 2 == start) ? randConsonant() : randVowel(); + for (let i = 0; i < keyLength; i++) { + text += i % 2 !== start ? randVowel() : randConsonant(); + } + + return text; } - return text; - } - };