checkChromosome.js (8kyu 94)

Codewars 알고리즘 풀이


Problem

  • The sperm cell determines the sex of an individual.
    • 정자 세포는 개인의 성별을 결정한다.
  • If a sperm cell containing an X chromosome fertilizes an egg, the resulting zygote will be XX or female.
    • X 염색체를 포함하는 정자 세포가 난자를 수정시키는 경우, 수정란은 XX 또는 암컷이 된다.
  • If the sperm cell contains a Y chromosome, then resulting zygote will be XY or male.
    • Y 염색체를 포함하는 정자 세포가 난자를 수정시키는 경우, 수정란은 XY 또는 수컷이 된다.
  • Determine if the sex of the offspring will be male or female based on the X or Y chromosome present in the male’s sperm.
    • 수컷의 정자에 있는 X 또는 Y 염색체에 기초하여, 새끼의 성별이 수컷인지 암컷인지를 결정한다.


Solution 01

function checkChromosome(sperm) {
  return sperm === 'XX' ? 'female' : 'male';
}

checkChromosome('XX');  // female
checkChromosome('XY');  // male


Solution 02

function checkChromosome(sperm) {
  return sperm[1] === 'X' ? 'female' : 'male';
}

checkChromosome('XX');  // female
checkChromosome('XY');  // male