Skip to content

Instantly share code, notes, and snippets.

@mbolt35
Created November 1, 2012 02:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbolt35/3991279 to your computer and use it in GitHub Desktop.
Save mbolt35/3991279 to your computer and use it in GitHub Desktop.
/**
* So, if I want to create a new Vector.<int> that
* appends 3, 2, 1 without modifying the original,
* I need to create *another* new Vector.<int>, just
* to pass the values to concat(). That's one extra
* Vector.<int> instantiation. Three total Vector.<int>
* objects, while only 2 should be needed:
* -- One, the original vec:Vector.<int>.
* -- Two, the new <int>[ 3, 2, 1 ] to pass the concat()
* parameter.
* -- Three, the result:Vector.<int>
*/
var vec:Vector.<int> = new <int>[ 1, 2, 3 ];
var result:Vector.<int> = vec.concat( new <int>[ 3, 2, 1 ] );
trace(result);
/**
* Or, we can save the trouble of creating an extra
* Vector.<int> by shallow copy and appending the
* 3, 2, 1 manually:
*/
var vec:Vector.<int> = new <int>[ 1, 2, 3 ];
// Shallow Vector.<int> copy
var result:Vector.<int> = vec.concat();
result.push(3, 2, 1);
trace(result);
// Outputs: 1,2,3,3,2,1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment