Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

grid-neighbors-1d

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grid-neighbors-1d

Get the 8 closest neighbours of a cell in a 2d grid when flattened to a 1d array

  • 0.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11
increased by120%
Maintainers
1
Weekly downloads
 
Created
Source

grid-neighbors-1d

Get the 8 closest neighbours of a grid with edge wrapping from a 1d array

Why?

grid-neighbors

Usage

Get the neighbours of cell 12 in a 5x6 grid:

const gn = require('grid-neighbors-1d');
const neighbors = gn(12, 5, 6);
console.log(neighbours); // [6, 7, 8, 11, 13, 16, 17, 18]

grid-neighbors returns an array of indexes where:

  • neighbors[0] = north west neighbor
  • neighbors[1] = north neighbor
  • neighbors[2] = north east neighbor
  • neighbors[3] = west neighbor
  • neighbors[4] = east neighbor
  • neighbors[5] = south west neighbor
  • neighbors[6] = south neighbor
  • neighbors[7] = south east neighbor

License

(C) 2019 P. Hughes. All rights reserved.

Shared under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported license.

Keywords

FAQs

Package last updated on 10 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc