1.6 KiB
1.6 KiB
id | title | challengeType | videoUrl | forumTopicId | dashedName |
---|---|---|---|---|---|
bd7123c9c452eddfaeb5bdef | Usar notação de colchetes para descobrir o enésimo caractere antes do último em uma string | 1 | https://scrimba.com/c/cw4vkh9 | 18344 | use-bracket-notation-to-find-the-nth-to-last-character-in-a-string |
--description--
Você pode usar o mesmo princípio que nós acabamos de usar para recuperar o último caractere em uma string, para recuperar o enésimo caractere antes do último caractere.
Por exemplo, você pode pegar o valor da antepenúltima letra da string const firstName = "Augusta"
usando firstName[firstName.length - 3]
Exemplo:
const firstName = "Augusta";
const thirdToLastLetter = firstName[firstName.length - 3];
thirdToLastLetter
teria o valor da string s
.
--instructions--
Use notação de colchetes para descobrir o penúltimo caractere na string lastName
.
Dica: tente olhar o exemplo acima se você ficar travado.
--hints--
secondToLastLetterOfLastName
deve ser a letra c
.
assert(secondToLastLetterOfLastName === 'c');
Você deve usar .length
para pegar a penúltima letra.
assert(code.match(/\.length/g).length > 0);
--seed--
--after-user-code--
(function(v){return v;})(secondToLastLetterOfLastName);
--seed-contents--
// Setup
const lastName = "Lovelace";
// Only change code below this line
const secondToLastLetterOfLastName = lastName; // Change this line
--solutions--
const lastName = "Lovelace";
const secondToLastLetterOfLastName = lastName[lastName.length - 2];