Constructor
new AgentArray(…args)
Creates an instance of AgentArray. Simply pass-through to super() now, but may add initialization code later.
Name | Type | Attributes | Description |
---|---|---|---|
args | * | <repeatable> | Zero or more items in Array |
- Source
let aa = new AgentArray({x:0,y:0}, {x:0,y:1}, {x:1,y:0})
//=> [{ x: 0, y: 0 }, { x: 0, y: 1 }, { x: 1, y: 0 }]
Methods
(static) fromArray(array) → {AgentArray}
Convert an existing Array to an AgentArray "in place". Use array.slice() if a new array is wanted
Name | Type | Description |
---|---|---|
array | Array | Array to convert to AgentArray |
- Source
array converted to AgentArray
- Type:
- AgentArray
toArray() → {Array}
See World and MyClass's foo property. Convert this AgentArray to Array in-place
- Source
This AgentArray converted to Array
- Type:
- Array
isEmpty() → {boolean}
Return true if there are no items in this Array
- Source
- Type:
- boolean
new AgentArray().isEmpty()
//=> true
aa.isEmpty()
//=> false
first() → {any}
Return first item in this array. Returns undefined if empty.
- Source
- Type:
- any
aa.first()
//=> { x: 0, y: 0 }
last() → {any}
Return last item in this array. Returns undefined if empty.
- Source
- Type:
- any
aa.last()
//=> { x: 1, y: 0 }
atIndex() → {any}
Return at index. Returns undefined if empty. Wrap the index to be within the array.
- Source
- Type:
- any
aa.atIndex(aa.length)
//=> { x: 0, y: 0 }
all(fcn) → {boolean}
Return true if fcn(element) returns true for each element in this array. Same as Array.every, using NetLogo's name
Name | Type | Description |
---|---|---|
fcn | function | fcn(element) return boolean |
- Source
true if fcn returns true for all elements
- Type:
- boolean
props(key, typeopt) → {Array}
Return array of property values from this array's objects. Array type is specified, defaults to AgentArray
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
key | String | Property name | ||
type | Array | <optional> | AgentArray | Type of array (Array, Uint8Array, ...) |
- Source
Array of given type
- Type:
- Array
aa.props('x')
//=> [0, 0, 1]
aa.props('y')
//=> [0, 1, 0]
typedSample(obj) → {Object}
Creates an Object of Arrays, one Array per each property in obj. Obj is key, arrayType pairs: x: Float32Array This is advanced, used for web workers, very large data sets, and remote communication
Name | Type | Description |
---|---|---|
obj | Object | Object of prop, array type pairs |
- Source
- Type:
- Object
aa.typedSample({x: Uint8Array, y: Uint8Array})
//=> {x: new Uint8Array([0, 0, 1]), y: new Uint8Array([0, 1, 0])}
uniq() → {AgentArray}
Return new AgentArray of the unique values of this array
- Source
- Type:
- AgentArray
forLoop(fcn) → {this}
Call fcn(agent, index, array) for each item in AgentArray. Index & array optional. Array assumed not mutable. Note: 5x+ faster than this.forEach(fcn)
Name | Type | Description |
---|---|---|
fcn | function | fcn(agent, [index], [array]) |
- Source
Return this for chaining.
- Type:
- this
ask(fcn)
Call fcn(agent, [ i, AgentArray ]) for each agent in AgentArray. where i = agent's array index and AgentArray is this array Array can shrink. If it grows, will not visit beyond original length. If it either shrinks or grows, it will console.log a message "ask" is NetLogo term.
Name | Type | Description |
---|---|---|
fcn | function | fcn(agent, [index], [array]) |
- Source
with(fcn) → {AgentArray}
Use: turtles.with(t => t.foo > 20).ask(t => t.bar = true)
Name | Type | Description |
---|---|---|
fcn | function | fcn(agent, [index], [array]) |
- Source
- Type:
- AgentArray
clone()
Create copy of this AgentArray
- Source
AgentArray
sortBy(reporter, ascendingopt) → {AgentArray}
Return this AgentArray sorted by the reporter in ascending/descending order. If reporter is a string, convert to a fcn returning that property.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
reporter | function | |||
ascending | boolean | <optional> | true |
- Source
- Type:
- AgentArray