Skip to content

Instantly share code, notes, and snippets.

@Lelith
Created March 11, 2020 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lelith/52ffe7322e9eb0c42d3a43f69405400f to your computer and use it in GitHub Desktop.
Save Lelith/52ffe7322e9eb0c42d3a43f69405400f to your computer and use it in GitHub Desktop.
longest password (60% solution, i tought needs to contain characters AND numbers)
// 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