Created
July 20, 2009 20:40
-
-
Save eligrey/150893 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var foo = <></>; // XMLList literal | |
foo.push(<n>0</n>, 1, 5, 3, 2, 6, 4); | |
foo.toXMLString() === "<n>0</n><n>1</n><n>5</n><n>3</n><n>2</n><n>6</n><n>4</n>"; | |
foo.sort(function(a, b) { | |
return a - b; | |
}).toXMLString() === "<n>0</n><n>1</n><n>2</n><n>3</n><n>4</n><n>5</n><n>6</n>"; | |
foo.filter(function(x) { // filter out integers less then 3 | |
if (!(x < 3)) | |
return true; | |
}).toXMLString() === "<n>3</n><n>4</n><n>5</n><n>6</n>"; | |
foo.slice(2, 5).toXMLString() === "<n>2</n><n>3</n><n>4</n>"; | |
foo.splice(2, 1, <n>9</n>, <n>8</n>).toXMLString() === "<n>2</n>"; | |
foo.slice(2, 5).toXMLString() === "<n>3</n><n>9</n><n>8</n>"; | |
foo.pop().toXMLString() === "<n>6</n>"; | |
foo.shift().toXMLString() === "<n>0</n>"; | |
foo.shift().toXMLString() === "<n>1</n>"; | |
foo.unshift(<bar/>); | |
foo.toXMLString() === "<bar/><n>3</n><n>9</n><n>8</n><n>4</n><n>5</n>"; | |
foo.map(parseFloat).forEach(function(n){ print(n) }) // prints NaN, 3, 9, 8, 4, 5 | |
foo.some(function(x) { // some are greater than 5 | |
if (x > 5) return true; | |
}) === true; | |
foo.every(function(x) { // all are numbers | |
if (typeof x == "number") return true | |
}) === false; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment