michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: /** michael@0: Filename: general2.js michael@0: Description: 'This tests out some of the functionality on methods on the Array objects' michael@0: michael@0: Author: Nick Lerissa michael@0: Date: Fri Feb 13 09:58:28 PST 1998 michael@0: */ michael@0: michael@0: var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; michael@0: var VERSION = 'no version'; michael@0: startTest(); michael@0: var TITLE = 'String:push,splice,concat,unshift,sort'; michael@0: michael@0: writeHeaderToLog('Executing script: general2.js'); michael@0: writeHeaderToLog( SECTION + " "+ TITLE); michael@0: michael@0: array1 = new Array(); michael@0: array2 = []; michael@0: size = 10; michael@0: michael@0: // this for loop populates array1 and array2 as follows: michael@0: // array1 = [0,1,2,3,4,....,size - 2,size - 1] michael@0: // array2 = [size - 1, size - 2,...,4,3,2,1,0] michael@0: for (var i = 0; i < size; i++) michael@0: { michael@0: array1.push(i); michael@0: array2.push(size - 1 - i); michael@0: } michael@0: michael@0: // the following for loop reverses the order of array1 so michael@0: // that it should be similarly ordered to array2 michael@0: for (i = array1.length; i > 0; i--) michael@0: { michael@0: array3 = array1.slice(1,i); michael@0: array1.splice(1,i-1); michael@0: array1 = array3.concat(array1); michael@0: } michael@0: michael@0: // the following for loop reverses the order of array1 michael@0: // and array2 michael@0: for (i = 0; i < size; i++) michael@0: { michael@0: array1.push(array1.shift()); michael@0: array2.unshift(array2.pop()); michael@0: } michael@0: michael@0: new TestCase( SECTION, "Array.push,pop,shift,unshift,slice,splice", true,String(array1) == String(array2)); michael@0: array1.sort(); michael@0: array2.sort(); michael@0: new TestCase( SECTION, "Array.sort", true,String(array1) == String(array2)); michael@0: michael@0: test(); michael@0: