hrishikeshparanjape / scala-array-js Goto Github PK
View Code? Open in Web Editor NEWtrying to implement this: "http://www.scala-lang.org/api/current/index.html#scala.collection.Seq" for JavaScript Array
trying to implement this: "http://www.scala-lang.org/api/current/index.html#scala.collection.Seq" for JavaScript Array
/* 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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.