Giter Site home page Giter Site logo

scalafy-arrays's Introduction

scalafy-arrays

scalafy-array is a tiny library to add some functionalities to JavaScript's Arrays.

The library adds several functions to improve Arrays use in JavaScript. These functions are written in JavaScript, and all methods were tested and are compatible with Firefox and Chrome.

Setup & Installation

This library is really to install just run the next command>

bower install scalafy-arrays

After this, everything will be downloaded in your default bower's folder or bower_components. So you have to add the library your html file.

<script src="bower_components/scalafy-arrays/dist/scalafy-arrays.js"></script>

What does it add?

  • count(f?) Counts the number of elements in array which satisfy a predicate (f) if f is not defined then it counts all elements.
var arr = [1, 2, 3, 4];
    
console.log(arr);    // 4
console.log(arr.count(function(e){     // 2
    return e % 2 === 0;
})); 
  • diff(that) Computes the multiset difference between this array and another array.
var arr = [1, 2, 3];
    
console.log(arr.diff([1,3]));    // [2]
  • distinct Finds all different elements in an array.
var arr = [1, 1, 2, 2, 3, 3];

console.log(arr.distinct());    // [1, 2, 3]
  • exists Tests whether a predicate holds for at least one element of this array.
console.log(arr.exists(function(e){    // true
    return e === 2;
}));    
  • filterNot Selects all elements of this array which don't satisfy a predicate. I.E. is like filter but the opposite.
var arr = [1, 2, 3, 4];

console.log(arr.filterNot(function(e){    // [1, 3]
    return e % 2 == 0;
}));
  • flatMap Receives a mapping function and executes the function for every element in the array and flatten the result.
var arr = [[1, 2], [3, 4]];

console.log(a.flatMap(e){ // [2, 4, 6, 8]
    return e * 2;
});
  • flatten similar to flatMap. Flattens a two-dimensional array by concatenating all its rows into a single array.
console.log(a.flatten());          // [1, 2, 3, 4] 
  • forall Tests whether a predicate holds for all elements of this array.
console.log(a.forall(function(e){ // true
    return e % 1 == 0;
}));

console.log(a.forall(function(e){ // false
    return e % 5 == 0;
}));

scalafy-arrays's People

Contributors

bonsanto avatar aparcero avatar

Stargazers

Favio André Vázquez avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.