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

157
Views
Function can accept character input and the number of loop

i have some question about logic,but i stuck in this question. i dont understand what this question means

Write a function with the following conditions:

  • Function can accept character input and the number of loop
  • Each of the first characters will be taken out from the string and input into a new string
  • Then every the number of inputs loop take out from the string and input into a new string
  • Do this until the characters in the string empty
  • Return the New Of String

Example:

function solution(string, numberOfLoop)
solution("MISTERALADIN",4) Output: MEAIANLTSRID

function Solution(string, numberOfLoop) {
  let newString = string[0];
  for (let i = 0; i < numberOfLoop; i++) {
    string = string.subs
    for (let j = 0; j < string.length; j++) {
      newString += string[j];
    }
  }
}

// function Solution (string, numberOfLoop) {
//   // console.log(string)
//   let newString = string[0]

// }

console.log(Solution("MISTERALADIN", 4));

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

0

The problem is very poorly written, apparently by someone who doesn't speak English well (unless you did the translation, then maybe you didn't translate it well).

The parameter "number of loop" doesn't really describe it well. It's not the number of iterations to perform, so you don't use it as the limit in a for loop.

Based on the example, it's the steps between characters to select. So it's the increment that you should add to to the iteration variable in the loop. The limit is the length of the string.

So what you're supposed to do is:

  1. Copy the characters at indexes 0, numberOfLoop, 2*numberOfLoop, 3*numberOfLoop, etc. to the result, and remove them from the input string.

  2. Repeat the above step until the input string is empty.

I'm not writing the solution for you. You asked what the question means, solving it is still your problem.

It will probably be easier to do this by first converting the string to an array (you can do this with the split() method), then you can use splice() to remove elements from it.

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!