Well,
I just got out of bed, so I can't tell you why exactly I used Object.assign beside that I remember observing on objects returned byt the game, that their type were not nececarily basic type[*], thus leaving some method calls with 'undefined is not a function'... that is when its returned value is assigned to a variable, otherwise, no error raised, and hell that is an unwelcomed change from Python or C#. Anyway, now I remember why I used it : I just didn't remebember if the returned object of creep.room.find were a real Array, I still have to remember how to test the type of an array, instead of 'typeof []', whom return value is not helpful [Object object] or something...
By the way, here is the code right now - will be slightly modified to handle cases where there is no containers - with the preceding section, you will notice that I also used Object.assign with no problems whatsoever in the first part:
let buildings = Object.assign([],creep.room.find(FIND_MY_STRUCTURES, { filter: function(structure){ return (structure.structureType == STRUCTURE_EXTENSION || structure.structureType == STRUCTURE_SPAWN); }}));assert(buildings.length > 0, 'spawns and extensions not detected in hauler AI');let lenBuildings = buildings.length;let tmp = creep.room.find( FIND_STRUCTURES, {filter: (s) => s.structureType == STRUCTURE_CONTAINER});assert(tmp[0].structureType == STRUCTURE_CONTAINER);buildings = buildings.concat(tmp);// buildings are filled first with spawns and extensions and only then containers are added to it.// so iterating over buildings, the first buildings will be spawns and extensions.assert(buildings.length > lenBuildings, 'container not detected in hauler AI');assert(buildings[lenBuildings].structureType == STRUCTURE_CONTAINER);
[*]:but maybe these observations were just the fruits of tireness...