Skip to main content
Jump to: navigation, search

Difference between revisions of "VJET/Typing Arrays with VJETDocs"

(New page: {color:#333333}In JavaScript there is the Array type.{color} Below {color:#333333}are examples of using JavaScript Array.{color}<br/> <!-- code start--> <pre style="margin-left:20px; fo...)
 
Line 1: Line 1:
 
{color:#333333}In JavaScript there is the Array type.{color} Below {color:#333333}are examples of using JavaScript Array.{color}<br/>
 
{color:#333333}In JavaScript there is the Array type.{color} Below {color:#333333}are examples of using JavaScript Array.{color}<br/>
 
+
<source lang="javascript">
 
+
 
+
<!-- code start-->
+
<pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd">
+
 
var browsers = ['Firefox', 'Chrome', 'Safari'] ; //< Array  
 
var browsers = ['Firefox', 'Chrome', 'Safari'] ; //< Array  
 
  var browsers = new Array('Firefox', 'Chrome', 'Safari') ; //< Array  
 
  var browsers = new Array('Firefox', 'Chrome', 'Safari') ; //< Array  
Line 11: Line 7:
 
  browsers[1] = 'Chrome' ;
 
  browsers[1] = 'Chrome' ;
 
  browsers[2] = 'Safari' ;  
 
  browsers[2] = 'Safari' ;  
</pre><!-- code end-->
+
</source>
 
+
  
 
What elements you put in the  array are up to you. In essence, any JavaScript object can be put in the  array. In our previous examples it appears that we only want browser  names in our Array. Actually we only want Strings from a typing  standpoint.&nbsp;
 
What elements you put in the  array are up to you. In essence, any JavaScript object can be put in the  array. In our previous examples it appears that we only want browser  names in our Array. Actually we only want Strings from a typing  standpoint.&nbsp;
Line 32: Line 27:
  
 
{color:#333333}An array with a single <nowiki>[[</nowiki><nowiki>]]</nowiki> pairs is called a single dimension array.&nbsp;{color}<br/>
 
{color:#333333}An array with a single <nowiki>[[</nowiki><nowiki>]]</nowiki> pairs is called a single dimension array.&nbsp;{color}<br/>
 
 
 
<source lang="javascript">
 
<source lang="javascript">
 
var out = vjo.sysout.println;  
 
var out = vjo.sysout.println;  
Line 52: Line 45:
  
 
{color:#333333}Here is an example of a two dimensional array of Number.{color}<br/>
 
{color:#333333}Here is an example of a two dimensional array of Number.{color}<br/>
 
 
 
 
<source lang="javascript">
 
<source lang="javascript">
 
var keys = [ //< Number[][]
 
var keys = [ //< Number[][]
Line 67: Line 57:
 
  vjo.sysout.println('total: ' + total) ;
 
  vjo.sysout.println('total: ' + total) ;
 
</source>
 
</source>
 
  
 
{color:#333333}console>&nbsp;total: 45&nbsp;{color}<br/>
 
{color:#333333}console>&nbsp;total: 45&nbsp;{color}<br/>

Revision as of 07:12, 1 December 2012

{color:#333333}In JavaScript there is the Array type.{color} Below {color:#333333}are examples of using JavaScript Array.{color}

var browsers = ['Firefox', 'Chrome', 'Safari'] ; //< Array 
 var browsers = new Array('Firefox', 'Chrome', 'Safari') ; //< Array 
 var browsers = new Array() ; //< Array
 browsers[0] = 'FireFox' ;
 browsers[1] = 'Chrome' ;
 browsers[2] = 'Safari' ;

What elements you put in the array are up to you. In essence, any JavaScript object can be put in the array. In our previous examples it appears that we only want browser names in our Array. Actually we only want Strings from a typing standpoint. 

{color:#333333}VJETDocs allows you to be very specific about what type you want your array to be. {color}


{color:#333333}{_}Array-Dimension{_}{color}{color:#333333} = "[[" "]]"{color} {color:#333333}Ex: [[]] {color}

{color:#333333}{_}Array-Dimensions{_}{color}{color:#333333} = one or more {color}{color:#333333}{_}Array-Dimension's{_}{color}{color:#333333} back to back{color}

{color:#333333}Ex: [[]][[]] or [[]][[]][[]] {color}

{color:#333333}Array-Type: {color}{color:#333333}{_}Limited-Type-Name{_}{color}{color:#333333} {color}{color:#333333}{_}Array-Dimensions{_}{color}{color:#333333} {color}

{color:#333333}Examples of a Vjet Array Type: String[[]] or Number[[]] or Date[[]][[]]or worker.Task[[]][[]][[]] {color}


{color:#333333}An array with a single [[]] pairs is called a single dimension array. {color}

var out = vjo.sysout.println; 
 var scores = [91, 77, 84] ; //< Number[]
 var names = ['Mark', 'Sean', 'Juan'] ; //< String[] 
 for(var i = 0; i < 3; i++) {
    var name = names[i] ; //< String
    var score = scores[i] ; //< Number
    out(name + ": " + score)

console> {color:#333333}Mark: 91{color} {color:#333333}Sean: 77{color} {color:#333333}Juan: 84 {color}

{color:#333333}It is possible to define arrays of arrays; these are called multi-dimension arrays. Multi-dimension arrays are defined by how many consecutive [[]] pairs. The number of [[]] pairs is often referred to as the n-dimensional array. Thus [[]][[]] means a 2 dimensional array and [[]][[]][[]] means a 3-dimensional array and so on. {color}{color:#333333}For example [[]][[]] is a two-dimensional array. [[]][[]][[]] is a three dimensional array and so on.{color}

{color:#333333}Here is an example of a two dimensional array of Number.{color}

var keys = [ //< Number[][]
 [1, 2, 3],
 [4, 5, 6],
 [7, 8, 9]
 ];
var total = 0 ; //< Number 
 for(var row = 0; row < 3; row++) {
 for (var col = 0; col < 3; col++) {
 total += keys[row][col] ;
 vjo.sysout.println('total: ' + total) ;

{color:#333333}console> total: 45 {color}

{color:#333333}We can have arrays of native types and vjet types. We can even have arrays of functions (we haven't described them yet). {color} {color:#333333}We can even have an array of type-reference (although it may not be too useful).{color}

Back to the top