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

176
Views
Hello, in this code I need to find exact place of letters, my code finds only place of one letter, but I want to find the place of 2 or more letters
const f = (newStr, givenWord) => {
  let arr = [...newStr];
  let newArr = [];

  for (let i = 0; i + Math.sqrt(arr.length) < arr.length + 1; i += Math.sqrt(arr.length)) {
    newArr.push(arr.slice(i, i + Math.sqrt(arr.length)))
  }

  console.log(newArr);

  for (let i = 0; i < newArr.length; i++) {
    for (let j = 0; j < newArr[i].length; j++) {
      if (newArr[i][j] == givenWord) {
        return [i, j];
      }
    }
  }
  return [-1, -1];
};

let result = f("QWEASDZXC", "A");
console.log(`[${result[0]} ${result[1]}]`);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try with this approach

(function(word, letters) {
    // Convert letters words in an array with indexes of each letter in the word
    const indexes = letters.split('').map(letter => word.indexOf(letter));
    return indexes.filter(index => index !== -1);
})('QWEASDZXC', 'AC');

Input

'QWEASDZXC' 
'AC'

Output received

[ 3, 8 ]
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!