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

212
Views
¿Cómo puedo recuperar la subcadena común entre el final de una cadena y el comienzo de otra cadena?

¿Hay alguna forma más simple (idealmente de una función integrada que me perdí del documento) para recuperar la subcadena común entre el final de una cadena y el comienzo de otra cadena? Por ejemplo, abc def y def ghi deberían devolver def .

 abcdef defghi ========= def

Mi implemento actual:

 const a = "abcdef"; const b = "defghi"; function findCommonEndStart(a, b) { let common = ""; for (let i = 1; i <= a.length; i++) { const sub = a.slice(-i, a.length); if (b.startsWith(sub)) { common = sub; } } return common; } console.log(findCommonEndStart(a, b));

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

0

Aquí como lo hice.

 let a = "abdef"; let b = "defdklc"; function func(x, y) { for (i in x) { if (x.substr(-i, x.length) == y.substr(0, i)) { console.log(x.substr(-i, x.length)) } } } func(a, b)

about 4 years ago · Juan Pablo Isaza Report

0

Parece que estás buscando una expresión regular simple:

 let str = 'abcdef defghi'; let find = str => str.match(/(\w+)\b.+\b(?:\1)/m)?.[1]; let result = find(str); // result = 'def'
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!