Skip to content

Instantly share code, notes, and snippets.

@jose-mdz
Created October 11, 2022 18:04
Show Gist options
  • Select an option

  • Save jose-mdz/536421e97888a5f38b6ae173154acbfe to your computer and use it in GitHub Desktop.

Select an option

Save jose-mdz/536421e97888a5f38b6ae173154acbfe to your computer and use it in GitHub Desktop.

Revisions

  1. jose-mdz created this gist Oct 11, 2022.
    2 changes: 2 additions & 0 deletions rows_cols.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    const getIndex = (row: number, col: number, width: number) => width * row + col;
    const getRowCol = (index: number, width: number) => [Math.floor(index / width), index % width];