pyarray
TypeScript icon, indicating that this package has built-in type declarations

1.2.1 • Public • Published

pyarray logo
pyarray

A node module for manipulating arrays just like how you would in Python!



Build Status

Install

NPM

Features

  • Supports all native javascript array methods, such as push, indexOf etc.
  • Supports native Python list methods too!
  • Not only that, but you can also use index ranges and negative indexes, no more array[array.length-1]

Methods

For detailed information about pyarray's method behaviour visit Python's official docs. Even the errors are the same!

Python method Supported? Note
list.append(x) Yes Identical to Array.prototype.push
list.extend(L) Yes
list.insert(i, x) Yes
list.remove(x) Yes
list.pop([i]) Yes Renamed to pypop to avoid conflict with Array.prototype.pop
list.index(x) Yes
list.count(x) Yes
list.reverse() Yes Identical to Array.prototype.reverse
list.sort() No

Examples

import pyarray from 'pyarray'

Creating a pyarray

let fruits = pyarray(['Banana', 'Apple', 'Orange', 'Plum', 'Grape'])

Accessing elements

Python pyarray Result
fruits fruits.get() ['Banana', 'Apple', 'Orange', 'Plum', 'Grape']
fruits[0] fruits[0] 'Banana'
fruits[-1] fruits[-1] 'Grape'
fruits[0:-2] fruits['0:-2'] ['Banana', 'Apple', 'Orange']
fruits[0:-1:2] fruits['0:-1:2'] ['Banana', 'Orange']
fruits[::-1] fruits['::-1'] ['Grape', 'Plum', 'Orange', 'Apple', 'Banana']

You can also use the .get() method as a fallback, the syntax is obj.get(start, end, step)

Testing

  1. Install dependencies $ npm install

  2. Run tests $ npm run test

  3. View coverage

$ istanbul cover node_modules\mocha\bin\_mocha -- dist/tests
$ open coverage/lcov-report/index.html

Readme

Keywords

Package Sidebar

Install

npm i pyarray

Weekly Downloads

3

Version

1.2.1

License

ISC

Last publish

Collaborators

  • gigobyte