Files
freeCodeCamp/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-nth-to-last-character-in-a-string.md
2021-10-27 21:47:35 +05:30

1.6 KiB

id, title, challengeType, videoUrl, forumTopicId, dashedName
id title challengeType videoUrl forumTopicId dashedName
bd7123c9c452eddfaeb5bdef Usare la notazione parentesi per trovare l'n-ultimo carattere dalla fine di una stringa 1 https://scrimba.com/c/cw4vkh9 18344 use-bracket-notation-to-find-the-nth-to-last-character-in-a-string

--description--

È possibile utilizzare lo stesso principio che abbiamo appena usato per recuperare l'ultimo carattere in una stringa per recuperare il carattere n-ultimo dalla fine.

Ad esempio, puoi ottenere il valore della terzultima lettera della stringa const firstName = "Augusta" usando firstName[firstName.length - 3]

Esempio:

const firstName = "Augusta";
const thirdToLastLetter = firstName[firstName.length - 3];

thirdToLastLetter dovrebbe avere un valore stringa s.

--instructions--

Usa la notazione a parentesi per trovare il penultimo carattere nella stringa lastName.

Suggerimento: Prova a guardare l'esempio qui sopra se ti blocchi.

--hints--

secondToLastLetterOfLastName dovrebbe essere la lettera c.

assert(secondToLastLetterOfLastName === 'c');

Dovresti usare .length per ottenere la penultima lettera.

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];