Created
March 11, 2020 17:37
-
-
Save Lelith/52ffe7322e9eb0c42d3a43f69405400f to your computer and use it in GitHub Desktop.
longest password (60% solution, i tought needs to contain characters AND numbers)
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
// you can write to stdout for debugging purposes, e.g. | |
// console.log('this is a debug message'); | |
function isOdd(num){return num%2} | |
function solution(S) { | |
let solution = -1; | |
const passwords = S.split(' '); | |
const possiblePW = passwords.filter((password)=>{ | |
if(password.length > 2 && !password.match(/\W/g)){ | |
const characters = password.match(/\D/g); | |
const digits = password.match(/\d/g); | |
if(characters && digits){ | |
if(isOdd(digits.length) && !isOdd(characters.length)){ | |
return password; | |
} | |
} | |
} | |
}); | |
if(possiblePW.length>0) { | |
solution = Math.max(...(possiblePW.map(el => el.length))); | |
} | |
return solution; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment