const spiral = (rowNum, colNum) => { return Array(rowNum) .fill(Array(colNum).fill()) .map((x, r) => x.map((_, c) => { return +( // top (r < rowNum / 2 && r % 2 === 0 && r - 2 <= c && c <= colNum - r - 1) || // right (c > (colNum - 2) / 2 && (colNum - c) % 2 === 1 && colNum - c - 2 < r && r <= rowNum - (colNum - c)) || // bottom (r > rowNum / 2 && (rowNum - r) % 2 === 1 && rowNum - r - 2 < c && c < colNum - (rowNum - r)) || // left (c < (colNum - 2) / 2 && c % 2 === 0 && r > c + 1 && r < rowNum - c) ); }) ); };
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Discussion on: Daily Challenge #98 - Make a Spiral
Replies for: Now I'm working on generalizing it to non square matrix
For further actions, you may consider blocking this person and/or reporting abuse