1.0.1 • Published 6 years ago

traverse-2d v1.0.1

Weekly downloads
3
License
ISC
Repository
github
Last release
6 years ago

Traverse-2d

Node version contributions welcome JavaScript Style Guide Known Vulnerabilities

Higher order generators for 2D arrays traversing

Table of Contents

Installation

npm i -S traverse-2d

Usage

This library provide a Traverser function which return an object with 4 methods to traverse a matrix :

  • fromTopLeft
  • fromTopRight
  • fromBottomLeft
  • fromBottomRight

They all take a matrix and return a generator

import Traverser from "traverser-2d"

const matrix = [[0, 1, 2, 3], [4, 5, 6], [7, 8, 9]]

// Take a yielder function called on each move in the matrix,
// a column and row predicate,
// which should return true if should go to the next col/row.
// Default functions are provided for all arguments
const T = Traverser()
const traversed = [...T.fromTopLeft(matrix)] // return [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

Support

Please open an issue for support.

Contributing

Please contribute using Github Flow. Create a branch, add commits, and open a pull request.