How to resolve the algorithm Arrays step by step in the Jsish programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Arrays step by step in the Jsish programming language

Table of Contents

Problem Statement

This task is about arrays. For hashes or associative arrays, please see Creating an Associative Array. For a definition and in-depth discussion of what an array is, see Array.

Show basic array syntax in your language. Basically, create an array, assign a value to it, and retrieve an element   (if available, show both fixed-length arrays and dynamic arrays, pushing a value into it). Please discuss at Village Pump:   Arrays.
Please merge code in from these obsolete tasks:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Arrays step by step in the Jsish programming language

Source code in the jsish programming language

/* Arrays in Jsi */
// Create a new array with length 0
var myArray = new Array();
;myArray;

// In Jsi, typeof [] is "array".  In ECMAScript, typeof [] is "object"
;typeof [];
 
// Create a new array with length 5
var myArray1 = new Array(5);
;myArray1;
 
// Create an array with 2 members (length is 2) 
var myArray2 = new Array("Item1","Item2");
;myArray2;
;myArray2.length;
 
// Create an array with 2 members using an array literal
var myArray3 = ["Item1", "Item2"];
;myArray3;
 
// Assign a value to member [2] (length is now 3)
myArray3[2] = 5;
;myArray3;
;myArray3.length;
 
var x = myArray3[2] + myArray3.length;   // 8
;x;
 
// You can also add a member to an array with the push function (length is now 4)
myArray3.push('Test');
;myArray3;
;myArray3.length;

// Empty array entries in a literal is a syntax error, elisions not allowed
//var badSyntax = [1,2,,4];


/*
=!EXPECTSTART!=
myArray ==> []
typeof [] ==> array
myArray1 ==> [ undefined, undefined, undefined, undefined, undefined ]
myArray2 ==> [ "Item1", "Item2" ]
myArray2.length ==> 2
myArray3 ==> [ "Item1", "Item2" ]
myArray3 ==> [ "Item1", "Item2", 5 ]
myArray3.length ==> 3
x ==> 8
myArray3 ==> [ "Item1", "Item2", 5, "Test" ]
myArray3.length ==> 4
=!EXPECTEND!=
*/

  

You may also check:How to resolve the algorithm Integer comparison step by step in the RPG programming language
You may also check:How to resolve the algorithm Calculating the value of e step by step in the V (Vlang) programming language
You may also check:How to resolve the algorithm Strip a set of characters from a string step by step in the Raku programming language
You may also check:How to resolve the algorithm FizzBuzz step by step in the Cubescript programming language
You may also check:How to resolve the algorithm Call a foreign-language function step by step in the Pascal programming language