'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));


Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Barmar