Arrays
Data Types
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 arraylet clonePoint = point; // clone for point to start counting from that number at begining of arraylet arr = [...Array(N).keys()] // generate array and fill with 0 to 10if(!(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)])
- }