Created
October 7, 2023 18:23
-
-
Save bonomiandreia/27c709f0b99f0515fa54e986d5cd9810 to your computer and use it in GitHub Desktop.
A password detection system similar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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