Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

541
Views
Javascript: obtenga el carácter enésimo de la cadena (JSChallenger)

Soy un novato total y actualmente estoy aprendiendo Javascript. Encontré este problema en JSChallenger y he estado luchando con él. Aquí está mi código:

 // Write a function that takes a string (a) and a number (n) as argument // Return the nth character of 'a' function myFunction(a, n) {let string = a; let index = n; return string.charAt(index); }

¿Alguien puede señalar mis errores? ¡Muchas gracias!

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

prueba este

 function myFunction(a, n){ return a[n - 1];}
about 4 years ago · Juan Pablo Isaza Report

0

// there is a shorter way to do this since you want to find what's missing here is what's missing. function myFunction(a, n){ let string = a; let index = n-1; return string.charAt(index); }
about 4 years ago · Juan Pablo Isaza Report

0

El índice de la cadena JS comienza a enumerar desde 0, por lo que la n debe disminuirse en 1

 // Write a function that takes a string (a) and a number (n) as argument // Return the nth character of 'a' function myFunction(a, n) { let string = a; let index = n; return string.charAt(index-1); }

la forma más fácil de escribirlo sería:

 // Write a function that takes a string (a) and a number (n) as argument // Return the nth character of 'a' function myFunction(a,n) { return a[n - 1]; }

Lo que significa devolver de la cadena "a" de myFunction el índice "[n-1]", "n-1" es una operación necesaria para obtener el índice correcto porque el índice de cadena comienza a enumerar desde 0.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!