Browse Source

Array.prototype.some instead of mutable var in forEach (#6)

This is the correct higher-order function for this task that doesn't make mutable state and also `some` will short-circuit once a true is found unlike the `forEach`.
pull/342/head
toastal 7 years ago
committed by Guillaume Vincent
parent
commit
fc7f09f56f
1 changed files with 3 additions and 7 deletions
  1. +3
    -7
      cli.js

+ 3
- 7
cli.js View File

@@ -69,13 +69,9 @@ function calcPassword(site, login, masterPassword, passwordProfile) {


function hasNoShortOption(options) {
let hasShortOption = false;
['l', 'u', 'd', 's'].forEach(function(shortOption) {
if (typeof options[shortOption] !== 'undefined' && options[shortOption]) {
hasShortOption = true;
}
});
return !hasShortOption;
return !(['l', 'u', 'd', 's'].some(function(shortOption) {
return typeof options[shortOption] !== 'undefined' && options[shortOption];
}));
}

function getOptionBoolean(options, optionString) {


Loading…
Cancel
Save