my javascript soloution to codeeval.com problems