Ad
Arrays
Data Types
Code
Diff
  • function func(N, point) {
      return funcHelper(N, point, [])
    }
    
    function funcHelper(N, x, arr) {
      return N === 0 ? arr : funcHelper(N - 1, x - 1, [...arr, Math.abs(x)])
    }
    • function func(N, point) {
    • let start = 0; // starting position of array
    • let clonePoint = point; // clone for point to start counting from that number at begining of array
    • let arr = [...Array(N).keys()] // generate array and fill with 0 to 10
    • if(!(point > N)) {
    • arr.forEach((o, index) => {
    • index < point ? arr[index] = clonePoint-- : arr[index] = start++;
    • });
    • return arr;
    • }
    • return [];
    • return funcHelper(N, point, [])
    • }
    • function funcHelper(N, x, arr) {
    • return N === 0 ? arr : funcHelper(N - 1, x - 1, [...arr, Math.abs(x)])
    • }