https://www.codewars.com/kata/5637b03c6be7e01d99000046
Codewars - Achieve mastery through coding practice and developer mentorship
A coding practice website for all programming levels – Join a community of over 3 million developers and improve your coding skills in over 55 programming languages!
www.codewars.com
DESCRIPTION:
One suggestion to build a satisfactory password is to start with a memorable phrase or sentence and make a password by extracting the first letter of each word.
Even better is to replace some of those letters with numbers (e.g., the letter O can be replaced with the number 0):
- instead of including i or I put the number 1 in the password;
- instead of including o or O put the number 0 in the password;
- instead of including s or S put the number 5 in the password.
Examples:
"Give me liberty or give me death" --> "Gml0gmd"
"Keep Calm and Carry On" --> "KCaC0"
코드
function makePassword(phrase) {
return phrase.split(' ').map(el => el[0].replace(/i/ig, 1).replace(/o/ig, 0).replace(/s/ig, 5)).join('');
}
댓글