How does this code work?
-
_.filter(Game.creeps, (creep) => creep.memory.role == 'harvester');
-
The examples here might be helpful: https://lodash.com/docs/3.10.1#filter
-
^ You can also click 'source' on that link-page and it will take you to the github for that lodash function.
https://github.com/lodash/lodash/blob/3.10.1/lodash.js#L6307
-
The _.filter() is used to check which elements in the passed array satisfy the condition. It will form a new array of all those elements which satisfy the condition passed from the array. This function takes the element from the list one by one and checks the specified operations on the code.
Syntax: _.filter( list, predicate, [context] ) Parameters: This function accept three parameters as mentioned above and described below:
list: This parameter is used to hold the list of items.
predicate: This parameter is used to hold the truth condition.
context: The text content which need to be display. It is optional parameter.
Return value: It returns an array consisting of elements which satisfy the condition.
-
Thank you all for replying, I am new to JavaScript and programming/coding as a whole, really only messed around with python semi-thoroughly