June 5th Codewar
This codewar was supposed to be for the 4th but the clock is my enemy. Specially since I always try to compete with it at the end of the day. Anyway today's codewar was a good one. You would be given either XY or XX and had to write a function that will return a statement each.
First I thought of doing a filter to filter out the XY. It did not pass the test maybe because I didn't write it out right?
function chromosomeCheck(sperm) {
return sperm.filter(n => n.length === 'XY'){
"Congratulations! You're going to have a son."
}else
return "Congratulations! You're going to have a daughter."
}
}
/* I used this function that I had used in the past...
function friend(friends){
return friends.filter(n => n.length === 4)
}
*/
Then I realized it had to think simple. It was and if then statement. If the parameter is equal to 'XY' then it will return son. Else it will return daughter. So my new attempt was this.
function chromosomeCheck(sperm) {
if (sperm === "XY"){
return "Congratulations! You're going to have a son."
}else {
return "Congratulations! You're going to have a daughter."
}
}
and I passed it! Yay last minute win!