Update phonetic.js

This commit is contained in:
wioniqle-q 2021-11-15 14:54:33 +03:00 committed by GitHub
commit 26b1617edf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,14 +1,10 @@
// Draws inspiration from pwgen and http://tools.arantius.com/password // Draws inspiration from pwgen and http://tools.arantius.com/password
// Helper methods to get an random vowel or consonant
const randOf = (collection) => { const randOf = (collection) => {
return () => { return () => {
return collection[Math.floor(Math.random() * collection.length)]; return collection[Math.floor(Math.random() * collection.length)];
}; };
}; }, randVowel = randOf('aeiou'), randConsonant = randOf('bcdfghjklmnpqrstvwxyz');
// Helper methods to get an random vowel or consonant
const randVowel = randOf('aeiou');
const randConsonant = randOf('bcdfghjklmnpqrstvwxyz');
module.exports = class PhoneticKeyGenerator { module.exports = class PhoneticKeyGenerator {
@ -18,7 +14,7 @@ module.exports = class PhoneticKeyGenerator {
const start = Math.round(Math.random()); const start = Math.round(Math.random());
for (let i = 0; i < keyLength; i++) { for (let i = 0; i < keyLength; i++) {
text += (i % 2 == start) ? randConsonant() : randVowel(); text += i % 2 !== start ? randVowel() : randConsonant();
} }
return text; return text;