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

js-array-ext

v1.1.0

Published

JavaScript Array Extension

Downloads

14

Readme

travis build results

JavaScript Array Extension

A small library with array generic operations.

Philosophy under the hood

I think that most of the time what algorithm's programer does is iterate in different ways over one or many list of element and for each iteration applying a process. Some of those iteration are simply join, intersection, etc, in the other occasions could be no so easy to see which is the generic iteration/operation we need.

In this small library I try to do basically four things:

  • Add basic Array's iterations.
  • Add basic operation over Sorted Arrays with unduplicated values, I call those type of arrays as srtf (Sorted and Filtered).
  • Add complex Array's iterations.
  • Add complex iterations over srtf Arrays.

All the functions in this library are built base on current JS Array methods (see https://www.w3schools.com/jsref/jsref_obj_array.asp) as much as possible or in function defined in this library.

Installation

npm install js-array-ext

API

  • Markdown style documentation: API-MD
  • HTML style documentation: API-HTML

Usage

import idtArray from 'js-array-ext';
var srt = [0, 1, 2, 3, 4, 5];
var compareNumber = (num1, num2) => num1 - num2;
var srtSliceFind = idtArray.sliceFind(srt, 3, compareNumber);

Output should be [3, 4, 5]

Comparisons

Before

var xCoords = [3, 4, 6, 8];
var yCoords = [1, 5, 2, 4];
var points = [];
xCoords.forEach(x => yCoords.forEach(y, => points.push({x, y}) ) );

After

import idtArray from 'js-array-ext';
var xCoords = [3, 4, 6, 8];
var yCoords = [1, 5, 2, 4];
// We provide the combine function, we do not need call twice forEach anymore.
var points = idtArray.combine(xCoords, yCoords, (x, y) => ({x, y}));

Bonus

If we want a new list of sorted points base on point distance to origin (0, 0) we can just do:

var DD = p => p.x * p.x + p.y * p.y; // DD is for Delta * Delta.
var PPDistance = (p1, p2) => DD(p1) - DD(p2);
var srtPnts = idtArray.sort(points, PPDistance);

Tests

npm test

Future Functions

splitFilter(array, processFunction)

Split array in tree Array, one for elements in which processFunction return negative number, one for case return cero and one for case return positive numbers.

reduceMap(array, processFunction, reduceFunction, initial)

Call to processFunction for each element and and push each result in an Array. Then call to reduceFunction in same way as Array.reduce. Default for initial is an empty Array and default for reduceFunction is Array.concat

Contributing

So far only my self.