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

142
Views
¿Cómo encontrar la letra del medio entre las letras especificadas?

Creé una función que acepta 2 parámetros para encontrar el valor medio entre esos parámetros en una variable Alphabet .

Ejemplo:

 the middle part between Q and U is S, the middle part between R and U is ST, the middle part between T and Z is W,

Lo que me confunde es cómo tomo el valor uno por uno comenzando en el índice 1 en la variable Alphabet .

 function letterMiddleValue(a, b) { let alpha1 = Alphabet.indexOf(a); let alpha2 = Alphabet.indexOf(b); let center = (alpha1 + alpha2) / 2; let letterLength; if (center % 2 == 1) { letterLength = 1; } else { letterLength = 2; } return Alphabet.substring(center, center + letterLength); } var Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; console.log(letterMiddleValue("Q", "U")); console.log(letterMiddleValue("R", "U")); console.log(letterMiddleValue("T", "Z"));

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

0

El centro para r & u es 18.5. 18,5 % 2 es 0,5, por lo que debe verificar la condición 0,5:

 function letterMiddleValue(a, b) { let alpha1 = Alphabet.indexOf(a); let alpha2 = Alphabet.indexOf(b); let center = (alpha1 + alpha2) / 2; let letterLength; if (center % 2 == 0.5) { letterLength = 2; } else { letterLength = 1; } return Alphabet.substring(center, center + letterLength); } var Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; console.log(letterMiddleValue("Q", "U")); console.log(letterMiddleValue("R", "U")); console.log(letterMiddleValue("T", "Z"));

Eso es porque cómo calculas el centro. (7 + 5) / 2 = 6,5 (6 + 10) / 2 = 8 y módulo devuelve lo que no es divisible por 2

about 4 years ago · Juan Pablo Isaza Report

0

Creo que hay un enfoque alternativo, que es solo calcular la distancia entre ellos y luego decidir si extraer uno o dos caracteres.

Esto también hace frente a que no haya nada en medio, o que el valor b baje más abajo en el alfabeto (o no esté en el Alfabeto definido)

 function letterMiddleValue(a, b) { const aPos = Alphabet.indexOf(a); const bPos = Alphabet.indexOf(b); const len = bPos - aPos if (len < 2) { return '[none]' } const start = aPos + (len / 2) const end = start + 1 + (len % 2) return Alphabet.slice(Math.floor(start), end) } const Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; console.log(letterMiddleValue("Q", "U")); // S console.log(letterMiddleValue("R", "U")); // ST console.log(letterMiddleValue("T", "Z")); // W console.log(letterMiddleValue("A", "B")); // none console.log(letterMiddleValue("A", "C")); // B console.log(letterMiddleValue("A", "D")); // BC console.log(letterMiddleValue("A", "A")); // none console.log(letterMiddleValue("Z", "A")); // none console.log(letterMiddleValue("z", "A")); // none console.log(letterMiddleValue("Z", "a")); // none

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!