Last active
October 7, 2020 22:59
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
import _ from 'lodash'; | |
function getNotInGuess(secret,guess){ | |
let guess_ = guess.slice(); | |
let res = []; | |
secret.map(el => { | |
if (guess_.includes(el)) { | |
guess_.splice(guess_.indexOf(el),1); | |
} else { res.push(el) } | |
}) | |
return res | |
} | |
function getScore(guess, secret){ | |
if(guess.length === 4 && secret.length === 4){ | |
let guess_ = _.map(guess, x => x.num), | |
secret_ = _.map(secret, x => x.num), | |
zip_ = _.zip(guess_,secret_), | |
rights = _.map(zip_, x => { | |
if(x[0] === x[1]){ return 1} | |
else { return 0} }), | |
rights_ = _.reduce(rights, (x,y) => x + y, 0), | |
sNotInGuess = _.difference(secret_,guess_), | |
wrongs_ = secret.length - sNotInGuess.length - rights_ | |
return {guess: guess, blacks: rights_, whites: wrongs_} | |
} else { | |
return {} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment