npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@zekumoru-dev/knights-travails

v1.1.0

Published

The eighth project of the JavaScript course from The Odin Project.

Downloads

2

Readme

Knights Travails

The eighth project of the JavaScript course from The Odin Project.

Suppose a knight piece is placed somewhere on the chess board and it needs to move to another location on the board (or its current location!), find the shortest path from the knight's location to that location.

graph.findPath([4, 3], [3, 3])

Result

[
  ChessVertex { value: '(3, 4)' },
  ChessVertex { value: '(4, 6)' },
  ChessVertex { value: '(2, 5)' },
  ChessVertex { value: '(3, 3)' }
]

The value is in cartesian coordinate starting from the top-right while the findPath method has parameters ([startRow, startCol], [endRow, endCol]) (also starting from the top-right) hence why the first value (3, 4) in the result is different (or swapped) from the input [4, 3].

Documentation

Node

Constructor

Node(value)

Creates a Node instance with the given value.

Members

value

Returns the node's value.

neighbors

Returns the array of the node's neighbors. The array is frozen so it cannot be modified. Check out Object.freeze for more info.

Methods

addNeighbor

addNeighbor(node)

Adds the given node as a new neighbor, same goes to node. If the node is itself or it's already a neighbor, ignores it.

Returns undefined.

removeNeighbor

removeNeighbor(node)

Removes the given node from the neighbors, same goes to node. If the node is itself or it does not have node as a neighbor, ignores it.

Returns undefined.

hasNeighbor

hasNeighbor(node)

Returns true if a node has the given node as a neighbor, otherwise false.

toString

toString()

Returns the string representation of a node. Syntax: ( value ) => [ nVal1, nVal2, ..., null ].

ChessVertex

Constructor

ChessVertex(row, col)

Creates a ChessVertex instance with the given row and col positions.

Members

row

Returns the row position.

col

Returns the column position.

Methods

toString()

Returns the string representation. Syntax: [row][col] ( value ) => [ nVal1, nVal2, ..., null ].

ChessGraph

Constructor

ChessGraph()

Creates a ChessGraph instance.

Initializes its member variable vertices to a 8x8 two-dimensional array each containing a ChessVertex which simulates a chess board.

Members

vertices

Returns the two-dimensional array of the chess board.

Methods

addNeighbor

addNeighbor([startRow, startCol], [endRow, endCol])

Connects the two given cells with the positions [startRow, startCol] and [endRow, endCol] as neighbors.

If any of the four parameters is invalid, either a negative number or greater than the size of the board, the method does nothing.

Returns undefined.

findPath

findPath([startRow, startCol], [endRow, endCol], fns = {})

Returns an array of ChessVertex containing the shortest path from position [startRow, startCol] to position [endRow, endCol].

If any of the four parameters is invalid, returns an empty array.

There are events that will be invoked within the findPath method and to listen to them, pass in the event functions in the fns object.

fns = {
  onTraversal(node) { /* ... */ },
  onQueued(node, parentNode) { /* ... */ },
  onDequeued(node, previousNode) { /* ... */ },
}

toString

toString()

Returns a string representation of the graph.

Syntax

[
  [
    ChessVertex,
    ...
  ],
  ...
]

KnightGraph

Constructor

KnightGraph()

Creates a KnightGraph instance which connects all the vertices to their proper neighbors.

Proper neighbors means the neighbors of each cell when making a knight's move.

Members

Same as ChessGraph.

Methods

Same as ChessGraph.