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

es6-array-compose

v0.1.1

Published

Create a proxy joining two arrays in a single one, while still being sepparated arrays

Downloads

5

Readme

es6-array-compose

This package adds a new method to the array prototype, allowing to chain arrays in a single virtual array.

Usage

    require('es6-array-compose');

    var arr1 = [1,2];
    var arr2 = [5,6];

    arr = arr1.compose(arr2);

    console.log('(%s) %s', arr.length, arr); // (4) [1,2,5,6]
    arr1.push(3);
    console.log('(%s) %s', arr.length, arr); // (5) [1,2,3,5,6]
    arr2.shift(4);
    console.log('(%s) %s', arr.length, arr); // (5) [1,2,3,4,5,6]

Equality

ES6 proxies are (and there are good reasons for that) opaque. Which means that no matter what:

var arr = arr1.compose(arr2);

arr !== arr1.concat(arr2); //true
arr != arr1.concat(arr2); //true

As a workaround, you can check equality this way:

arr.equals(arr1.concat(arr2)) //true
arr.equals(arr1.concat(arr2)) //true

Which of course is much slower than the regular equality operation

Cool stuff you can potentially do with it

These are just examples, it doesn't mean that it's a good idea to do things like this, but it will give you some ideas, don't hesitate to share with me any use you may find for this.

Priority queues

  var p1 = [f1,f2,f3];
  var p2 = [f4,f5,f6];

  var p = p1.compose(p2);

  p.reduce((prev, cur) => return prev.push(cur()), []);
  // This will run all the processes, starting from the p1 priority list, and return an array of all the return values

Board games

Please, note that you should not modify the amount of objects from the list, using push, pop, shift, splice or unshift, since there is no way to know on which array will the element end.


var deck = [
  'A♥','2♥','3♥','4♥','5♥','6♥','7♥','8♥','9♥','10♥','J♥','Q♥','K♥',
  'A♦','2♦','3♦','4♦','5♦','6♦','7♦','8♦','9♦','10♦','J♦','Q♦','K♦',
  'A♣','2♣','3♣','4♣','5♣','6♣','7♣','8♣','9♣','10♣','J♣','Q♣','K♣',
  'A♠','2♠','3♠','4♠','5♠','6♠','7♠','8♠','9♠','10♠','J♠','Q♠','K♠'
];

var p1, p2, p3, p4, board, deck;

// Two cards for each player, and five in the board
p1.push(deck.pop());
p1.push(deck.pop());
p2.push(deck.pop());
p2.push(deck.pop());
p3.push(deck.pop());
p3.push(deck.pop());
p4.push(deck.pop());
p4.push(deck.pop());
board.push(deck.pop());
board.push(deck.pop());
board.push(deck.pop());
board.push(deck.pop());
board.push(deck.pop());

var game = p1.compose(p2).compose(p3).compose(p4).compose(board).compose(deck);

console.log(game);

function shuffle(array) {
  var currentIndex = array.length, temporaryValue, randomIndex ;

  // While there remain elements to shuffle...
  while (0 !== currentIndex) {

    // Pick a remaining element...
    randomIndex = Math.floor(Math.random() * currentIndex);
    currentIndex -= 1;

    // And swap it with the current element.
    temporaryValue = array[currentIndex];
    array[currentIndex] = array[randomIndex];
    array[randomIndex] = temporaryValue;
  }

  return array;
}

console.log(game);