1.2.1 • Published 8 years ago

pyarray v1.2.1

Weekly downloads
16
License
ISC
Repository
github
Last release
8 years ago

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 methodSupported?Note
list.append(x)YesIdentical to Array.prototype.push
list.extend(L)Yes
list.insert(i, x)Yes
list.remove(x)Yes
list.pop([i])YesRenamed to pypop to avoid conflict with Array.prototype.pop
list.index(x)Yes
list.count(x)Yes
list.reverse()YesIdentical 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

PythonpyarrayResult
fruitsfruits.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
1.2.1

8 years ago

1.2.0

8 years ago

1.1.0

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago