`
hideto
  • 浏览: 2678828 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

ASCB阅读笔记五、Arrays

阅读更多
var array:Array = new Array();

array.push("val 1", "val 2");
array[array.length] = "val 3";
array.unshift("z");

trace(array.shift());
trace(array.pop());

for (var i:int = 0; i < array.length; i++) {
  trace(array[i]);
}

trace(ArrayUtilities.findMatchIndices(array, "val"));

array.splice(0, 2);
array.splice(1, 0, "r", "s", "t");

var list:String = "Peter Piper picked a peck of pickled peppers";

var words:Array = list.split(" ");

trace(words.join("|"));

var newWords:Array = words.concat();
var newWords2:Array = words.slice(0);
var newWords3:Array = ArrayUtilities.duplicate(words, true);

words.sort();
words.sort(Array.DESCENDING);
words.sort(Array.CASEINSENSITIVE);

var scores:Array = [10, 2, 2, 1, 1, 14, 5, 8, 20, 19, 6];
scores.sort(Array.NUMERIC);

var sortedScores:Object = scores.sort(Array.UNIQUESORT);
trace(sortedScores);
trace(scores);

var words:Array = ["tricycle", "relative", "aardvark", "jargon"];
var indices:Array = words.sort(Array.RETURNINDEXEDARRAY);
trace(words);
trace(indices);
for(var i:int = 0; i < words.length; i++) {
  trace(words[indices[i]]);
}

words.sort(Array.CASEINSENSITIVE | Array.DESCENDING);
words.reverse();

var cars:Array = new Array(  );
cars.push({make: "Honda",    year: 1997, color: "maroon"});
cars.push({make: "Chrysler", year: 2000, color: "beige"});
cars.push({make: "Mercedes", year: 1985, color: "blue"});
cars.push({make: "Fiat",     year: 1983, color: "gray"});
cars.push({make: "Honda",    year: 1992, color: "silver"});
cars.push({make: "Chrysler", year: 1968, color: "gold"});
cars.push({make: "Mercedes", year: 1975, color: "green"});
cars.push({make: "Fiat",     year: 1983, color: "black"});
cars.push({make: "Honda",    year: 2001, color: "blue"});
cars.push({make: "Chrysler", year: 2004, color: "orange"});
cars.push({make: "Mercedes", year: 2000, color: "white"});
cars.push({make: "Fiat",     year: 1975, color: "yellow"});
cars.sortOn(["year", "make"]);
cars.sortOn("year", Array.DESCENDING);

var bands:Array = ["The Clash",
                   "The Who",
                   "Led Zeppelin",
                   "The Beatles",
                   "Aerosmith",
                   "Cream"];
function bandNameSort(band1:String, band2:String):int
{
  band1 = band1.toLowerCase();
  band2 = band2.toLowerCase();
  if(band1.substr(0,4) == "the ") {
    band1 = band1.substr(4);
  }
  if(band2.substr(0,4) == "the ") {
    band2 = band2.substr(4);
  }
  if(band1 < band2) {
    return -1;
  }
  else {
    return 1;
  }
}
bands.sort(bandNameSort);

var numbers:Array = new Array();
for(var i:int=0;i<20;i++) {
  numbers[i] = i;
}
function randomSort(elementA:Object, elementB:Object):Number {
  return Math.random() - .5
}
numbers.sort(randomSort);

var scores:Array = [10, 4, 15, 8];
scores.sort(Array.NUMERIC);
trace("Minimum: " + scores[0]);
trace("Maximum: " + scores[scores.length - 1]);

var letters:Array = ["a", "b", "c", "d"];
var lettersPointer:Array = letters;
trace(letters == lettersPointer);    // Display: true

var letters1:Array = ["a", "b", "c", "d"];
var letters2:Array = ["a", "b", "c", "d"];
trace(letters1 == letters2);    // Display: false

var equivalent:Boolean = true;
for(var i:int = 0; i < letters1.length; i++) {
  if(letters1[i] != letters2[i]) {
    equivalent = false;
    break;
  }
}
trace(equivalent);    // Display: true
trace(ArrayUtilities.equals(letter1, letters2));    // Display: true

var letters1:Array = ["a", "b", "c", "d"];
var letters2:Array = ["b", "a", "d", "c"];
trace(ArrayUtilities.equals(letters1, letters2));
// Displays: false
trace(ArrayUtilities.equals(letters1, letters2, true));
// Displays: true

public static function equals(arrayA:Array, 
                              arrayB:Array,
                              bNotOrdered:Boolean):Boolean {

    // If the two arrays don't have the same number of elements,
    // they obviously are not equivalent.
    if(arrayA.length != arrayB.length) {
        return false;
    }

    // Create a copy of each so that anything done to the copies 
    // doesn't affect the originals.
    var arrayACopy:Array = arrayA.concat(  );
    var arrayBCopy:Array = arrayB.concat(  );

    // If the order of the elements of the two arrays doesn't 
    // matter, sort the two copies so the order of the copies 
    // matches when comparing.
    if(bNotOrdered) {
        arrayACopy.sort(  );
        arrayBCopy.sort(  );
    }

    // Loop through each element of the arrays, and compare them. 
    // If they don't match, delete the copies and return false.
    for(var i:int = 0; i < arrayACopy.length; i++) {
        if(arrayACopy[i] != arrayBCopy[i]) {
            delete arrayACopy;
            delete arrayBCopy;
            return false;
        }
    }

    // Otherwise the arrays are equivalent. 
    // So delete the copies and return true.
    delete arrayACopy;
    delete arrayBCopy;
    return true;
}

var members:Object = {a: "A", b: "B", c: "C"};

var members:Object = {};
members.a = "A";
members.b = "B";
members.c = "C";
trace(members.a);
trace(members["a"]);

var members:Object = new Object();
members.a = "A";
members.b = "B";
members.c = "C";

for (var m:String in members) {
  trace(members[m]);
}
分享到:
评论

相关推荐

    FLEX的ASCB函数包

    ASCB函数包是专门为FLEX开发者设计的一个实用工具集,它扩展了FLEX的基础功能,尤其在处理字符串、数字以及日期等方面提供了便捷的函数操作。 首先,ASCB包中的“ASCB”可能是“ActionScript Custom Bundle”的缩写...

    ActionScript ascb包

    在本场景中,"ascb包"似乎是一个与ActionScript相关的库或者框架,它被设计为解压后放入项目的`src`目录下。由于没有提供更具体的详细信息,我们只能基于ActionScript的基础知识来展开讨论。 1. **ActionScript基础...

    ascb hardware card

    This manual describes the Goebel NIC, a test resource for exercising ASCB-D interface bus on Honeywell EPIC programs. This is a new generation of test equipment designed specifically for simulation.

    ascb.drawing.Pen 类

    但是大多数的图形用Graphics API还是很难画出的,AS3CBLibrary (http://www.rightactionscript.com/ascb) 提供了一个 ascb.drawing.Pen 类。Pen 类是Graphics 类的代理(包装)类。你可以构造一个新的Pen 实例然后...

    ascb.drawing.pen

    但是大多数的图形用Graphics API还是很难画出的,AS3CBLibrary (http://www.rightactionscript.com/ascb) 提供了一个 ascb.drawing.Pen 类。Pen 类是Graphics 类的代理(包装)类。你可以构造一个新的Pen 实例然后...

    安科瑞ASCB1系列智能微型断路器样本

    【安科瑞ASCB1系列智能微型断路器】是安科瑞电气股份有限公司推出的一款创新的智慧用电解决方案,旨在提升低压终端配电网络的安全性、可靠性和智能化水平。该系列产品包含智能微型断路器和智能网关两部分,广泛应用...

    591 ASCB1系列智能微型断路器安装使用说明书V1.00-20220715

    "591 ASCB1系列智能微型断路器安装使用说明书V1.00-20220715" 在本文中,我们将对ASCB1系列智能微型断路器的安装使用说明书进行详细的解读和分析。 首先,让我们从概述开始。根据手册的描述,ASCB1系列智能微型...

    flash actionscript3 as3游戏开发教程合集(2本经典合一)+AS3CBLibrary_ascb包.zip

    同时,通过阅读"ActionScript 3.0 Cookbook 中文版",可以学习到如何解决开发过程中遇到的实际问题,提升编程技能。 总之,《Flash ActionScript3 AS3游戏开发教程合集》是为那些希望通过AS3进行游戏开发的学习者...

    AS3CBLibrary

    库中的“ascb”包可能是所有类和接口的顶级命名空间,方便组织和管理代码。 在AS3中,类库通常包含了各种类和接口,它们可以是: 1. **动画类**:用于创建复杂的动画效果,可能包括时间轴控制、帧率管理、缓动函数...

    VB6.0与vb.net对照表

    - `AscB`:VB6.0的`AscB`函数对应VB.NET的`Microsoft.VisualBasic.Strings.Asc`函数。 - `Atn`:VB6.0的`Atn`函数对应VB.NET的`System.Math.Atan`方法。 - `AutoRedraw`:VB6.0的属性在VB.NET中没有直接对应,但...

    flash as3.0游戏

    一款带有代码的flash小游戏,直接下载,马上可以打开,不用解压缩.

    ASP封装成DLL

    ASP 封装成 DLL 服务器端组件 本文档主要讲述了如何将 ASP 封装成 DLL 服务器端组件,从而实现 ASP 程序在 IIS 上的运行。... 在 IIS 被请求执行一个 ASP 程序时,它首先会在 ASP 文件中找到 &lt;%%&gt; 标签之间的代码,...

    用VBS获取网页源代码.vbs

    ThisCharCode = AscB(MidB(vIn,i,1)) If ThisCharCode ; Then strReturn = strReturn & Chr(ThisCharCode) Else NextCharCode = AscB(MidB(vIn,i+1,1)) strReturn = strReturn & Chr(CLng(ThisCharCode) * &...

    鲜花网站建设

    if AscB(upfile_5xSoft_Stream.Read(1))&lt;&gt;AscB(MidB(Str,j,1)) then InString=0 Exit For end if next if InString&lt;&gt;0 then Exit Function end if next End Function Private Sub Class_Terminate form....

    VBS 16进制验证特定字符

    `AscB`函数则将这个字节转换为其对应的ASCII码,以便与16进制数值进行比较。如果从第12到18个字节的ASCII码对应于16进制数'f', 'a', 's', 't', 's', 'l', 'z'(即字符'fastslz'),则说明文件中包含预期的字符序列,...

    VB 从二进制流中恢复汉字信息

    strss = 256 * AscB(MidB(StringBin, intCount, 1)) + AscB(MidB(StringBin, intCount + 1, 1)) getString = getString & Chr(strss) intCount = intCount + 2 End If Loop End Function ``` 通过以上讨论和...

    asp_base64.rar

    arrData(i + 3) = AscB(MidB(strInput, i + 3, 1)) Next Base64ToBinary = arrData End Function ``` 4. **使用场景**:在ASP中,Base64编码通常用于: - 在HTTP头部传输非ASCII字符,如JSON Web Tokens (JWT)...

    获取中文字符串长度的函数

    `AscB`和`MidB`函数用于获取字符串中的字节,`And`操作符用于检查字节的最高位。如果连续的两个字节满足条件,说明它们构成一个中文字符,计数器加1。 在实际应用中,`CLen`函数对于处理包含中文字符的文本非常有用...

    vb字符串操作函数

    **用途:** AscB函数用于获取指定字符的单字节编码值。 **语法:** ``` MyVal = AscB("指定字符") ``` **示例:** ```vb MyVal = AscB("A") ' MyVal 的值为 65 MyVal = AscB("С") ' MyVal 的值为 15 ``` **注意...

Global site tag (gtag.js) - Google Analytics