Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bonomiandreia/27c709f0b99f0515fa54e986d5cd9810 to your computer and use it in GitHub Desktop.
Save bonomiandreia/27c709f0b99f0515fa54e986d5cd9810 to your computer and use it in GitHub Desktop.
A password detection system similar
function countMinimumOperations(password) {
let operations = 0;
let vowels = 0;
let consonants = 0;
// Count the number of vowels and consonants in the password
for (let i = 0; i < password.length; i++) {
const char = password[i];
if ('aeiou'.includes(char)) {
vowels++;
} else {
consonants++;
}
}
// Calculate the absolute difference between vowels and consonants
const diff = Math.abs(vowels - consonants);
// Calculate the minimum number of operations required to make it similar
operations = Math.floor(diff / 2);
return operations;
}
// Example usage:
const password = "hack";
const result = countMinimumOperations(password);
console.log(result); // Output: 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment