Ad
Arrays
Data Types
Code
Diff
  • const func = (N, p) => Array(N).fill().map((_,i)=>Math.abs(i-p));
    • 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 [];
    • }
    • const func = (N, p) => Array(N).fill().map((_,i)=>Math.abs(i-p));