← Back to challenges

Strong Password Checker

JavaScriptHardlogicnumbershigher_order_functionsfunctional_programming

Instructions

A password is considered strong if all the following conditions are met:

  1. It has at least 8 characters and at most 20 characters.
  2. It contains at least one lowercase letter, one uppercase letter and one digit.
  3. It must NOT contain three repeating characters in a row (e.g. "...aaa..." is weak, but "...aa...a..." is strong, assuming other conditions are met).

Write a function that takes a string str and return the MINIMUM change required to make it a strong password. If it's already strong, return 0.

Examples

strongPasswordChecker("Mypass!") ➞ 1
// 7 characters total, need to add one more digit for a strong password.

strongPasswordChecker("mypass1!") ➞ 1
// 8 characters total, need to add an uppercase letter.

strongPasswordChecker("ABCDEFGHIJKLMNOPQRSTU") ➞ 3
// 21 characters, only uppercase, need to delete one and replace two.

strongPasswordChecker("Mypaaaass!1") ➞ 1
// Contains 4 'a's in a row.

Notes

  • Insertion, deletion or replacement of any one character is considered one change.
  • Spaces will be ignored for this challange.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.