I'm still at my card game. Again and again I have such places as now where I can't get any further. I have two hands with cards. I want to output the names and suits as an array. But that only works with a two-digit combination. As soon as there is a 10 it is three digits and it no longer works.
'use strict'
let hand1 = ['7H', '2H', 'QH', '9H', '5H']
let hand2 = ['7H', '2H', 'QH', '10H', '5H']
let toSuit = hand => hand.map(a => a[0])
let toName = hand => hand.map(a => a[1])
console.log(toName(hand1))
console.log(toSuit(hand1))
console.log(toName(hand2))
console.log(toSuit(hand2))
I can do that for the single card but not for the output as an array.
'use strict'
let card1 = '9H'
let card2 = '10H'
let toSuit1 = card => card.charAt(card.length - 1)
let toName1 = card => card.slice(0,-1)
console.log(toSuit1(card1))
console.log(toSuit1(card2))
console.log(toName1(card1))
console.log(toName1(card2))
Thanks @blex
'use strict'
let hand1 = ['7H', '2H', 'QH', '9H', '5H']
let hand2 = ['7H', '2H', 'QH', '10H', '5H']
let toSuit1 = card => card.charAt(card.length - 1);
let toName1 = card => card.slice(0,-1);
let toSuit = hand => hand.map(toSuit1)
let toName = hand => hand.map(toName1)
console.log(toName(hand1))
console.log(toSuit(hand1))
console.log(toName(hand2))
console.log(toSuit(hand2))
toSuit = hand => hand.map(toSuit1); toName = hand => hand.map(toName1);