A function, written without any loop statements, that accepts an array and produces a new array equal to the initial array with ith element (1-based) repeated i times.

computer science

Description

TAIL RECURSION. A function, written without any loop statements, that accepts an array and produces a new array equal to the initial array with ith element (1-based) repeated i times.


here is the code with the loop I came up with, I just need to convert this to non-loop statements

export function stretched(a) {
    const stretchedArray = [];
    for (let [indexitemof a.entries()) {
      for (let i = 0i < index + 1i++) {
        stretchedArray.push(item);
      }
    }
    return stretchedArray;
}



Related Questions in computer science category