MCPcopy Create free account
hub / github.com/corbanbrook/dsp.js / createArrayList

Function createArrayList

examples/js/processing.js:3544–3608  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

3542
3543 p.ArrayList = function() {
3544 var createArrayList = function(args){
3545 var array = [];
3546 for (var i = 0; i < args[0]; i++){
3547 array[i] = (args.length > 1 ? createArrayList(args.slice(1)) : 0 );
3548 }
3549
3550 array.get = function(i) {
3551 return this[i];
3552 };
3553 array.contains = function(item) {
3554 return this.indexOf(item) !== -1;
3555 };
3556 array.add = function() {
3557 if(arguments.length === 1) {
3558 this.push(arguments[0]); // for add(Object)
3559 } else if(arguments.length === 2) {
3560 if (typeof arguments[0] === 'number') {
3561 if (arguments[0] >= 0 && arguments[0] <= this.length) {
3562 this.splice(arguments[0], 0, arguments[1]); // for add(i, Object)
3563 } else {
3564 throw(arguments[0] + " is not a valid index");
3565 }
3566 } else {
3567 throw(typeof arguments[0] + " is not a number");
3568 }
3569 } else {
3570 throw("Please use the proper number of parameters.");
3571 }
3572 };
3573 array.set = function() {
3574 if(arguments.length === 2) {
3575 if (typeof arguments[0] === 'number') {
3576 if (arguments[0] >= 0 && arguments[0] < this.length) {
3577 this.splice(arguments[0], 1, arguments[1]);
3578 } else {
3579 throw(arguments[0] + " is not a valid index.");
3580 }
3581 } else {
3582 throw(typeof arguments[0] + " is not a number");
3583 }
3584 } else {
3585 throw("Please use the proper number of parameters.");
3586 }
3587 };
3588 array.size = function() {
3589 return this.length;
3590 };
3591 array.clear = function() {
3592 this.length = 0;
3593 };
3594 array.remove = function(i) {
3595 return this.splice(i, 1)[0];
3596 };
3597 array.isEmpty = function() {
3598 return !!this.length;
3599 };
3600 array.clone = function() {
3601 return this.slice(0);

Callers 1

processing.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected