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';
}
};
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.