Modo entrevista. Cronômetro de 5 min, sem dicas e sem autocompletar
Card type by the first four digits
FácilBasics5 min
Write a function cardType(cardNumber) that finds the card type from the first four digits of a card number.
cardNumberis a string of exactly 16 digits, without spaces. It can start with0.- Add up the first four digits. If the sum is
16, return'Visa', otherwise return'Master'. - Return exactly
'Visa'or'Master', with a capital first letter.
Why a string: a 16-digit card number does not always fit exactly into a JavaScript number. For example, Number('9999999999999999') gives 10000000000000000.
Exemplos
cardType('4552720412345678')Retorna 'Visa'
cardType('5100123412341234')Retorna 'Master'
cardType('0790100000000000')Retorna 'Visa'
Cobrada em Luxoft · Fonte
Carregando o editor...
- Entrada
cardType('4552720412345678')Esperado'Visa' - Entrada
cardType('5100123412341234')Esperado'Master' - Entrada
cardType('0790100000000000')Esperado'Visa'
Os testes ocultos rodam no envio