Files
freeCodeCamp/curriculum/challenges/ukrainian/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-nth-to-last-character-in-a-string.md
2023-01-30 18:58:54 +02:00

1.9 KiB
Raw Blame History

id, title, challengeType, videoUrl, forumTopicId, dashedName
id title challengeType videoUrl forumTopicId dashedName
bd7123c9c452eddfaeb5bdef Дужкова нотація для пошуку n-го символа з кінця рядка 1 https://scrimba.com/c/cw4vkh9 18344 use-bracket-notation-to-find-the-nth-to-last-character-in-a-string

--description--

Ви можете використати той самий принцип, який ми щойно використовували для отримання останнього символу в рядку, щоб отримати n-ий символ з кінця.

Наприклад, ви можете отримати значення третьої з кінця літери рядка const firstName = "Augusta", використавши firstName[firstName.length - 3]

Приклад:

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

thirdToLastLetter матиме значення рядка s.

--instructions--

Використайте дужкову нотацію, щоб знайти другий з кінця символ у рядку lastName.

Підказка: якщо застрягли, перегляньте вищеподаний приклад.

--hints--

secondToLastLetterOfLastName має бути літера c.

assert(secondToLastLetterOfLastName === 'c');

Ви повинні використати .length, щоб отримати передостанню літеру.

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