Kunjan Kshetri avatar Kunjan Kshetri committed 7138d03

Adding documentation

Comments (0)

Files changed (1)

Documentation.aspx

+
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head><title>
+	Kunjan Kshetri Homepage: ASP.NET JavaScript jQuery Experiments
+</title><link rel="stylesheet" type="text/css" href="../style.css" media="screen" />
+<style type ="text/css">
+    pre { border : dotted; background-color:Silver;}
+
+</style>
+</head>
+
+<body >
+
+   <div id="top">
+		<ul>
+			<li><a href="http://net35.ccs.neu.edu/home/kunjan/">HOME</a></li>
+			<li><a href="http://net35.ccs.neu.edu/home/kunjan/Xperiments/Default.aspx">XPERIMENTS</a></li>
+			<li><a href="http://net35.ccs.neu.edu/home/kunjan/Project/Default.aspx">PROJECT</a></li>
+			<li><a href="http://net35.ccs.neu.edu/home/kunjan/Sources/Default.aspx">SOURCES</a></li>
+			<li><a href="http://net35.ccs.neu.edu/home/kunjan/Blog/Default.aspx">BLOG</a></li>
+			<li><a href="http://net35.ccs.neu.edu/home/kunjan/Links/Default.aspx">LINKS</a></li>
+						
+		</ul>
+	</div>
+<br /><br />
+<div id= "gap"> </div>
+<div id = "outer">
+	<div id = "content" >
+    <form name="aspnetForm" method="post" action="Documentation.aspx" id="aspnetForm">
+<div>
+<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTY1NDU2MTA1MmRkbojF2Ybhk4qpEFqy2EKoCIYyVgQ=" />
+</div>
+
+    
+        
+All Profiling were done using Firebug in Firefox.
+<h3>Build List</h3>
+    Build of List of X length with a certain property.  <br />
+    <pre><b><b>Definition</b></b>
+build_list(length): builds a list of specified length  starting from 0
+
+build_list(length,map_function,): builds a list of specified length  and maps the function to each item
+
+build_list(map_function,start, length): builds a list with starting and ending index; 
+    
+    
+<b>Usage</b>
+build_list(10)                 ->[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
+build_list(Math.sqrt,5)        ->[0, 1, 1.4142135623730951, 1.7320508075688772, 2]
+
+build_list(Math.sqrt,1,5)      ->[1, 1.4142135623730951, 1.7320508075688772, 2,2.23606797749979]
+              
+              
+<b>Time</b> :  build_list(Math.sqrt,10000)   -> 5 ms (individual time)
+        build_list(1000000);          ->4 seconds (individual time)
+        
+        Series of Operation Test:
+        build_list(1000).map(Math.sin)); [builds a 1000 element list and finds sine of each]
+        build_list(1000).map(Math.sin, 2)); [finds the sine of each of 1000 element twice]
+        build_list(1000).map(Math.sin, Math.abs)); [find sine and take their absolute value for 1000]
+        
+        Took 16 seconds to for the operations in firefox. Remember that sine is an expensive function
+</pre>      
+
+<h3>Common Builds</h3>
+
+     <h3>Zero-Array(zero vector)</h3>
+       Build a Zero Vector of specified length
+      <pre><b><b>Definition</b>
+      </b>build_zero(length)
+      <b>Funtion</b>:     Builds a zero 1D vector/array of  specified length
+      <b>Time</b>:        6ms for 1000 length vector, 53 ms for 10000 length vector
+      <b>Usage</b>:       build_zero(3)-> [0,0,0]</pre>
+
+
+     <h3> Unit-Array(Unit vector)</h3>
+      Build a Unit Vector of specified length
+      <pre>build_unit(length)
+      Function:   Builds a  unit 1D vector/array of  specified length
+      <b>Time</b>:       4 ms for 1000 length vector, 52 ms for 10000 length vector
+      <b>Usage</b>:      build_unit(3)-> [1,1,1]
+      
+      </pre>
+
+    
+   
+     <h3> Map </h3>
+       Maps the function to each of the item in the array    
+       This doesnt alter the array but returns a new one
+ 
+       <pre><b>Definition</b>
+map(function)              : applies the function to each item in the list
+map(fuction1...functionN)  : applies function1, function2 to functionN to each item in the list
+ap(function,N)             : applies the function N number of times
+       
+<b>Usage</b>: 
+map(function)             : applies the function to each item in the list
+
+map(fuction1...functionN) : applies function1, function2 to functionN to each item in the list
+number_array.map(Math.sqrt,Math.ceil,Math.Log): Apply square root, ceiling and log functions 
+
+map(function,N)           : applies the function N number of times 
+build_list(10).map(function(x){return Math.pow(x,2)},2} -> build a list of 10 numbers and take the
+                                                           square of each number twice
+
+["Kunjan", "Kanak"].map(function(name) { return 'This is ' + name }, 2));
+  ->["This is This is Kunjan", "This is This is Kanak"]   
+
+Task: Find the second derivative of all the functions in the list
+      myFunctionList.map(Derivative,2)  
+
+Syntatic sugar:  -> changes all the numbers to upper_case     
+
+</pre>
+<h3>Up_case</h3>
+Changes all the elements to upper case
+<pre>
+Usage: ([1, 2, 3, 'a'].up_case()) - > ["1", "2", "3", "A"]   took 2 ms
+</pre>
+
+<h3>Down_case</h3>
+Changes all the elements to upper case
+<pre>
+Usage: ([1, 2, 3, 'A'].down_case()) - > ["1", "2", "3", "a"]   took 2 ms
+</pre>
+
+    <h3>Add</h3>
+     Add two arrays or add a scalar quantity to each element
+<pre><b><b>Definition</b></b>: 
+.add(N)     :adds scalar quantity N to all the elements in the array.
+.add(array) :adds two arrays  and returns a new one.
+      
+<b>Usage</b>: 
+ [1,2,3].add(1) -> [2,3,4]
+ [1,2,3,4].add[1,1,1]->[2,3,4] : Ignores all the elements that dont pair.
+ [1,2,3].add[1,1,1] -> [2,3,4] 
+</pre>   
+
+<h3>Mul</h3>
+Multiply the array by a scalar quantity.
+<pre><b><b>Definition</b></b>: 
+.mul(N)     :multiplies all the element by a scalar quantity                 
+      
+<b>Usage</b>:
+ [1,2,3].mul(1) -> [1,2,3]
+ [1,2,3].mul(Infinity) -> [Infinity,Infinity,Infinity]
+ [1,2,3].mul('a') -> [NaN,NaN,NaN] (NaN:Not a Number)   
+                  
+</pre>    
+
+<h3>Copy</h3>
+Make a Copy of your Array
+<pre><b>Definition</b>:         
+general_array.make_copy() -> array1     : Clones the Array object with all its properties and values      
+ 
+</pre>
+
+<h3>Sort_Immutable   </h3>  
+    Sort the array alphabetically      
+                   
+     <pre>
+<b>Definition</b>: Sort Mutates the same array. This doesnt mutate the old array     
+     <b>Usage</b>:
+        var general_array = ['b','a','c'];
+                
+        (general_array);            -> ['b','a',c']
+        var new_array = general_array.sort_immutable();
+        (new_array);                -> ['a','b','c']
+        
+        (general_array)             -> ['b','a','c']
+        
+        (general_array.sort())      
+        (general_array)             -> ['a','b','c']</pre>     
+ 
+ 
+<h3>Fold</h3>
+ 
+<pre><b>Definition</b>: 
+      .fold(map_function,base)   : folds the list using the mapping_function starting  from base
+
+      .fold(map_function)        : folds the list taking the base as a default
+                  
+            
+<b>Usage</b>:      	     var general_array = ['1', '2', '3', 1 ];
+                  
+                  general_array.fold(add, 0) -> 7
+                  general_array.fold(mul, 1))-> 6
+                  general_array.fold(add))   -> 7
+                  
+                  ['a'].fold(add, 0))        -> NaN(Not a Number)
+                  
+
+    //Useful functions that can be used with Fold.
+    add = function(x, y) { return Number(x) + Number(y); };
+    mul = function(x, y) { return Number(x) * Number(y); };
+    div = function(x, y) { return Number(x) / Number(y); };
+    sub = function(x, y) { return Number(x) - Number(y); };
+</pre>       
+    
+ 
+      <h3>Syntatic Sugar provided for fold </h3>
+    
+    <h3>Add_all</h3>
+      Add all the elements in the array.
+      <pre><b>Definition</b>: .add_all() : adds all the elements in the array                  
+            
+<b>Usage</b>:      	    var general_array = ['1', '2', '3', 1 ];
+                  general_array.add_all()    -> 7
+                  ['a'].add_all()            -> NaN
+</pre>                    
+   <h3> Mul_all</h3>
+      Multiply all the elements in the array
+      <pre><b>Definition</b>: .mul_all() : multplies all the elements in the array                  
+            
+      <b>Usage</b>:      var general_array = ['1', '2', '3', 1 ];
+                  general_array.mul_all()    -> 6
+                  ['a'].mul_all()            -> NaN </pre>                    
+<h3>Cumulate</h3>
+     Accumulate the elements in the array with X function
+<pre><b>Definition</b>:
+.cumulate(function, base): accumulates the array using the function starting from base
+
+.cumulate(function)      : accumulates using the default base 0
+.cumulate()              : accumulates using  the default function 'add'and base '0'                 
+            
+<b>Usage</b>:       
+  var general_array             = ['1', '2', '3', '4', -1, 0, 'a'];
+ (general_array.cumulate(add, 0));  -> [1, 3, 6, 10, 9, 9, NaN]
+ (general_array.cumulate(add));     -> [1, 3, 6, 10, 9, 9, NaN]
+ (general_array.cumulate());       -> [1, 3, 6, 10, 9, 9, NaN]
+ (general_array.cumulate(mul, 1));  -> [1, 2, 6, 24, -24, 0, NaN]
+ (general_array.cumulate(mul, 1, 1)); //extra arguments are ignored
+         
+         
+<b>Usage</b> : Could be used to accumulate the distances travelled.
+<b>Time </b> : Took 4 seconds for 100,000 records. Do not use for 1 million records.
+<b>Advise</b>: Filter the array to contain only numbers first
+</pre>   
+
+<h3>Filter_Out</h3>
+    Filter out unneeded elements from an array.
+      <pre><b>Definition</b>: .filter_out(function):     removes all the elements that do not satisfy condition
+                  
+<b>Usage</b>:       
+var general_array = [1, 2, 'a', 'Kunjan', 3, 5, 0, Infinity, NaN];
+general_array.filter_out(is_even);                     -->  [1, 3, 5]
+general_array.filter_out(function(x) { return x >=3; })); -->  [1, 2, "a", "Kunjan", 0, NaN]        
+ </pre>   
+ 
+                 
+ <h3>Extensions for Filters    </h3>            
+    
+<h3>Filter_Odd</h3>
+    Keep only the odd numbers in an array.
+        <pre><b>Definition</b>:  Keeps all the elements that are only odd 
+        
+<b>Usage</b>:
+var general_array = [1, 2, 'a', 'Kunjan', 3, 5, 0, Infinity, NaN];
+general_array.filter_odd-->       [1, 3, 5]
+
+<b>Time</b>
+Took 5 seconds for 1 million record.</pre>
+<h3>Filter_Even</h3>
+Keeps all the elements that are only even 
+<pre>
+var general_array = [1, 2, 'a', 'Kunjan', 3, 5, 0, Infinity, NaN]
+general_array.filter_even-->   [2, "a", "Kunjan", 0, Infinity, NaN] 
+<b>Time</b>
+Took 5 seconds for 1 million record.
+</pre>
+
+<h3>Filter_Equals</h3>
+
+<pre><b>Definition</b> :   .filter_equals(X) : Keeps all the elements that are equal to X.
+       
+<b>Usage</b>:  
+var general_array = [1, 1, 'a','a', 2, 3general_array.filter_equals('a')->       ["a", "a"] 
+<b>Time</b>
+Took 5 seconds for 1 million record.       
+</pre>   
+<h3>Has_Element</h3>
+    Check if the list has a certain element.
+       <pre><b>Definition</b>:  
+       .has_element(X)   : returns the number of X in the list
+       
+<b>Usage</b>:      		 general_array = [1, 2, 'a','a'];     
+                    general_array.has_element('a')   -> 2  
+<b>Time: </b> It took 5 seconds to find an element ina 1 million record</pre>        
+    
+<h3>Find_Match</h3>
+    Find an element that matches a property
+        <pre><b>Definition</b> :  
+.find_match(function,'direction') :Finds the  element matching the property or returns false
+        
+        '<b>direction</b>' could be ONE OF,
+        'first' : starts searching from the beginning and returns first match
+        'last'  : starts searching from the END 
+                        
+        .find_match(function)             :Finds the element with default direction 'first'
+                       
+<b>Usage</b>:        
+        var general_array = [1, '2', 1000, 'a', Infinity];
+        general_array.find_match(function(x) { return x > 1; });               -> 2
+        general_array.find_match(function(x) { return x == 2000; }, 'first')); ->false
+                      
+<b>Tasks</b>
+        1. Find (me the) first element (that is) 1000
+        general_array.find_match(function(x) { return x == 1000; }, 'first')); ->1000 
+        
+        2. Find the last person in this list who has this property(>1)
+         (array_match.find_match(function(x) { return x > 1; }, 'last')); -> Infinity
+ </pre>   
+
+
+<h3>Has</h3>
+    Check if the array has a certain property.
+<pre><b>Definition</b>:               
+.has(function,arg1)    
+
+	arg1 is one of,
+	'any'/'or'  : checks if ANY of the element in the array has the property mentioned
+	'all'/'and' : checks if ALL  of the elementS in the  array has the property      
+                        
+.has(function)               : the default arg1 is taken as any
+       
+       
+       <b>Usage</b>:  
+        var general_array = [1, 2, 'a', 'a'];       
+        
+        general_array.has(function(x) { return x > 1; })) -> true
+
+        Task:
+        1.(Does this) array have any even numbers?
+        general_array.has(is_even, 'any');                 -> true
+        
+        general_array.filter(is_even).has(is_even,'all');  -> true [filtered array has all even numbers]
+
+        2. (Are) all (the) elements (in the) array odd?
+        general_array.has(is_odd, 'all');                  -> false
+       
+  </pre>         
+
+<h3>Max</h3>
+       
+<pre><b>Definition</b>:   .max()            : returns the maximum element in the array
+       
+       
+<b>Usage</b>:            
+        var general_array = [Infinity, 1, 2, 3, 4];
+        general_array.max() -> Infinity
+        
+        var general_array2 = ['a', 'b', 'c'];
+        general_array2.max() -> 'c'
+
+<b>Time: </b>5 seconds for 1 million records</pre>          
+
+<h3>Min</h3>
+       
+<pre><b>Definition</b>:   .min()            : returns the minimum element in the array
+       
+       
+<b>Usage</b>:  
+          
+        var general_array = [Infinity, 1, 2, 3, 4];
+        general_array.min() -> 1
+        
+        var general_array2 = ['a', 'b', 'c'];
+        general_array2.min() -> 'a'  
+<b>Time</b>: 5 seconds for 1 million records       
+</pre>   
+
+<h3>Frequency</h3>
+  Finds the number of repeated Elements in the array.     
+<pre><b>Definition</b>:               
+.frequency(X)    : checks how many times an element occurs in the array       
+       
+<b>Usage</b>:  
+        var general_array = [1, 2, 1, '1', 'a', Infinity];
+        
+        (general_array.frequency(2));           -> 1
+        (general_array.frequency('1'));         -> 1 ['1' is different from 1]       
+        (general_array.frequency(1000));        -> 0
+        
+</pre>   
+    
+<h3>How_Many</h3>
+Syntatic sugar for frequency
+<pre><b>Definition</b>   :  .how_many(X):  counts the number of X in the list
+       
+<b>Usage:</b>
+       1. How many Infinity are there?
+          var general_array = [1, 2, 1, '1', 'a', Infinity];
+          (general_array.how_many(Infinity));           -> 1       
+       
+</pre>        
+
+<h3>Pair</h3>
+ Combine the two array element-wise
+<pre><b>Definition</b>: 
+.pair(Array)  :combines the two arrays by pairing corresponding elements
+              
+ [(Note: if the arrays are of unequal length the extra elements are ignored ]
+
+       
+<b>Usage</b>:  
+        var fname = ["kunjan", " kanak", " kiran"];
+        var lname = ["bikram", " kshetri", ];
+        
+     (fname.pair(lname));    ->  ["kunjan bikram", " kanak kshetri"] 
+                                    
+          
+        Task:
+        1. Hash the text file and return pair of word and hash value.
+        
+        var text = "Alice Alice in the wonderland";
+        var hashedfunction = function(word) { return word.charCodeAt(); };
+        
+        var hashedValues= text.split(" ").map(hashedfunction);
+        var pairs = text.split(" ").pair(hashedValues);
+       
+pairs -> ["Alice 65", "Alice 65", "in 105", "the 116", "wonderland 119"]
+        
+</pre>    
+    
+<h3>Dot</h3>
+    Find the dot product of equal Array
+<pre><b>Definition</b>:   .dot(Array)  :finds the DOT PRODUCT of two  EQUAL arrays/vector
+[if the arrays are not equal returns null]
+              
+       
+<b>Usage</b>:  
+	  var coordinates0 = ['0', 0, 0];    [can accept string characters]
+         var coordinates1 = [1, 3, 4];
+         var coordinates2 = [0, 3, 4, 5];
+         
+        (coordinates1.dot(coordinates0));    ->  7
+        (coordinates2.dot(coordinates0));    ->  null
+<b>Time</b>: 5 seconds for 1 million records
+</pre>   
+
+<h3>Cross</h3>
+Returns the Cross Product of two arrays       
+<pre><b>Definition</b>:   .cross(Array)  :finds the CROSS PRODUCT of the two arrays       
+       
+ [NOTE: if the arrays are not equal, it ignores extra elements of the second array]
+              
+       
+<b>Usage</b>:  
+var coordinates1 = [0, 3, 4];    [can accept string characters]
+var coordinates2 = [0, 3, 4];
+         
+         
+        (coordinates1.cross(coordinates2))  -> 	    [["0 0", "0 3", "0 4"], 
+                                                ["3 0", "3 3", "3 4"], 
+                                                ["4 0", "4 3", "4 4"]]
+                                                
+         var coordinates1 = [0, 3];
+         var coordinates2 = [1, 2,3];
+         
+        (coordinates1.cross(coordinates2)) ->         [["0 1", "0 2", "0 3"],
+                                                ["3 1", "3 2", "3 3"]] 
+      
+         var coordinates1 = [0, 3, 4];
+         var coordinates2 = [1, 2];
+         
+               
+        (coordinates1.cross(coordinates2)) ->         [["0 1", "0 2"],
+                                                ["3 1", "3 2"],
+                                                ["4 1", "4 2"]]
+         <b>Time:</b> 35 seconds for 100,000 records. Use only for smaller Data sets.
+</pre>   
+
+<h3>DISTANCE</h3>
+    Calculate the distance between two arrays.
+<pre><b>Definition</b>:   .distance(Array)  :finds the distance between two arrays/vector
+[if the arrays are not equal returns FALSE]
+              
+       
+<b>Usage</b>:  
+	  var coordinates0 = ['0', 0, 0];    [can accept string characters]
+         var coordinates1 = [0, 3, 4];
+         var coordinates2 = [0, 3, 4, 5];
+         
+        (coordinates1.distance(coordinates0));    ->  5
+        (coordinates2.distance(coordinates0));    ->  null  [unequal lengths]
+</pre>    
+
+<h3>Modulus</h3>
+    Find the modulus of the array.
+<pre><b>Definition</b>:   .modulus()   :finds the modulus/length from origin of array/vector
+                               
+       
+<b>Usage</b>:  
+var coordinates0 = ['0', 0, 0];    [accepts characters like '0']
+         var coordinates1 = [0, 3, 4];
+         
+         
+        (coordinates0.modulus());    ->  0
+        (coordinates1.modulus());    ->  5
+<b>Time:</b> 4 seconds for 1 million records
+</pre>   
+ 
+    
+      <h3>Number Extensions </h3> 
+    
+      <h3>is_even / is_odd</h3>
+       
+       <pre><b>Definition</b>:                    finds if the number is even or odd
+      
+<b>Usage</b>:  
+        var num = 6;
+        num.is_even();               -> true
+        num.is_odd();                -> false
+        
+        num = 0;
+        num.is_even();               -> true
+        
+        OR AS FUNCTION CALLS
+        
+        is_even(6)                   -> true
+        is_odd(7)                    -> true
+        is_even('a');                -> true
+        
+ </pre>   
+    
+              <h3>Boolean Extensions  </h3>
+     
+     <h3> OPERATOR EXTENSIONS</h3>
+  <pre><b>  As Operators</b>
+      XOR  
+         (true.XOR(true));     -> false
+         (true.XOR(false));    -> true
+         (false.XOR(true));    -> true
+         (false.XOR(false));   -> false
+        
+        
+        ("Nand");
+         (true.NAND(true));     -> false
+         (true.NAND(false));    -> true
+         (false.NAND(true));    -> true
+         (false.NAND(false));   -> true
+        
+         ("Nor");
+         (true.NOR(true));      -> false
+         (true.NOR(false));     -> false
+         (false.NOR(true));     -> false
+         (false.NOR(false));    -> true   
+         
+<b>Or as Functions</b>
+         XOR(true, true)        -> false
+         NAND(true,true)        -> false
+         NOR (true,true)        -> false
+         
+         XOR('a','b')           -> false
+         XOR(1,1)               -> false
+ </pre>
+   
+      <h3>Sum_Upto</h3>
+      Calculate the sum upto a certain number
+  <pre><b>Definition</b>
+  .sum_upto(X)   :finds the sum of the numbers upto  X
+                                     if X<=0 returns 0
+       
+<b>Usage</b>:  
+          sum_upto('1')     -> 1
+          sum_upto(0)       -> 0
+          sum_upto(1)       -> 1
+          sum_upto('-1')    -> 0
+          sum_upto(3)       -> 6
+          sum_upto(100012000)->5001200122006000       Time: 7ms
+ 
+</pre>   
+
+<h3>String Extension </h3>               
+<h3>first_char</h3>
+ <pre><b>Definition</b>
+.first_char()   :returns the first character of the string  returns null for empty stringstr       
+<b>Usage</b>:  
+         "abc".first_char()  -> "a"
+         "".first_char()     -> null
+</pre>
+
+<h3>.* (inspired by ruby's *)</h3>
+    Fast concatenation of string with itself
+ <pre> <b>Definition</b>:   .*(N)   :Fast Concatenation of  the string with itself N number 
+                              of Times  if N<=0 returns the string itself
+       
+<b>Usage</b>:  
+          "a".*(5);        -> "aaaaa"
+          "a".*(0);        -> "a"
+          "a".*(-1);       -> "a"
+          "a".*(1);        -> "a"
+        
+Time :
+A 50 character string concatenated with itself 100 times      =7ms
+A 2500 character string concatenated with itself 500 times    = 650ms.
+ </pre>   
+
+
+    </div>
+    </form>
+</div>
+
+<div id="footer">
+	<p>&copy;Spring 2009. Kunjan Bikram Kshetri. Web Development Course. </p>
+</div>
+
+</body>
+</html>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.