Giter VIP home page Giter VIP logo

scala-array-js's Introduction

/*
    Copyright(c) 2011 Hrishikesh Paranjape
    [email protected]
    http://www.github.com/hrishikeshparanjape
*/

JavaScript Library for Scala Style Sequence(seq) extending several operations on JS Array object

API Reference:

Array -->
    foldLeft( Object initialValue )( function( Object result, Object current ) : Object ) : Object
        Folds the array from left to right and evaluates curried function as array is traversed.
        Example:
        var arr=[1,2,3,4,5];
        arr.foldLeft(0)(function(result,current){return result+current}); //returns 15
        arr.foldLeft(1)(function(result,current){return result*current}); //returns 120
        Also see: http://www.scala-lang.org/api/current/index.html#scala.collection.Seq

    tail( ) : Array
        Gives the same array with first element removed (inspired from scheme (lst tail))
        Example:
        var arr=[1,2,3,4,5];
        arr.tail(); //returns [2,3,4,5]

    take( Number num ) : Array
        Selects first n elements
        Example:
        var arr=[1,2,3,4,5];
        arr.take(3); //returns [1,2,3]
        Also see: http://www.scala-lang.org/api/current/index.html#scala.collection.Seq

    takeRight( Number num ) : Array
        Selects last n elements
        Example:
        var arr=[1,2,3,4,5];
        arr.takeRight(3); //returns [3,4,5]
        Also see: http://www.scala-lang.org/api/current/index.html#scala.collection.Seq

    toIndexedArray( ) : Array[{index:i,value:v}]
        Converts this sequence to an indexed sequence.
        Example:
        var arr=[1,2,3,4,5];
        arr.toIndexedArray( ); //returns [{index:0,value:1},{index:1,value:2},...{index:4,value:5}]
        Also see: http://www.scala-lang.org/api/current/index.html#scala.collection.Seq

    find( function( Object o) : Boolean ) : Number
        Finds the first element of the sequence satisfying a predicate, if any
        Example:
        var arr=[1,2,3,4,5];
        arr.find(function(x){return (x % 3 == 0);}); //returns 2
        Also see: http://www.scala-lang.org/api/current/index.html#scala.collection.Seq

    first( ) : Object
        Returns first element of array
        Example:
        var arr=[1,2,3,4,5];
        arr.first(); //returns 1
        Also see: http://www.scala-lang.org/api/current/index.html#scala.collection.Seq

    last( ) : Object
        Returns last element of array
        Example:
        var arr=[1,2,3,4,5];
        arr.last(); //returns 5
        Also see: http://www.scala-lang.org/api/current/index.html#scala.collection.Seq

scala-array-js's People

Contributors

hrishikeshparanjape avatar

Stargazers

 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.