Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

369
Vistas
Solving 8 kyu Define a card suit Code Wars (in javascript)?

My function is listed below, but it doesn't seem to work. The deck is pre-loaded, and test uses 4 cards to go through the function. Am I missing something?

Kata Code Wars

https://www.codewars.com/kata/5a360620f28b82a711000047

function defineSuit(card) {

var x = card.split('');

if (x === '♣') {

return 'clubs';

} else if ( x === '♦') {

return 'diamonds';

} else if ( x === '♥') {

return 'hearts';

} else {

return 'spades';

}

};

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use substr(-1) instead split('')[1]. Both will work the same, but substr(-1) is a bit faster

function defineSuit(card) {

   var suit = card.substr(-1);
   switch(suit){
      case '♣': return 'clubs';
      case '♦': return 'diamonds';
      case '♥': return 'hearts';
      default: return 'spades';
   }

}

"switch" fits better for this porpuse than "if/else". But remeber to use "breaks" if you are not returning a value after each case.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda