Counting Equipped Weapons and Armors

One part of a script I'm working on includes counting the number of weapons and armors that all party members are equipped with, and for some reason I am having the hardest time getting this count. Please note I am very new to coding, and javascript, so I apologize if I'm not clear. 


Example: Equipment count is 0, and our adventuring group finds a chest. In the chest is 2 long swords and leather armor. Character A equips a long sword, Equipment counts goes to 1. Character B also equips a long sword, Equipment count goes to 2. 


Later on, character B finds he likes fighting with his fist, so he unequips his weapon, Equipment count goes back to 1. Then character 1 remembers they found the leather armor and equips it, having the Equipment count go back up to 2. Finally, character c equips the longsword character b didn't want, and Equipment count goes up to 3. 


About the closest thing I can find is too go through $gameParty.members and loop through .hasWeapon($dataWeapons), but I would have to script it for each character, and for each weapon, then count the boolean trues that come out of the script, but I'm even having a problem figuring out how to do that. 


Is there an easier way to do this? Am I making this harder than it really is? 


Thanks ahead of time for all help provided. 
Additional information:


Here is the snippet of code that I was using to attempt to count if a weapon was equipped or not (this doesn't count armor yet).


var member0weapon = 0;
var i = 0;
while (i < 999){
var member0weapontest = Boolean($gameParty.members()[0].hasWeapon($dataWeapons));
if (Boolean(member0weapontest)); {
var member0weapon = 1;
};
i++
};


The problem I ran into is that the above code will always return "1", regardless of if member 0 is equipped with a weapon or not.


The reason I did it this way, is if I do the following: console.log($gameParty.members()[0].hasWeapon($dataWeapons[1])) and member 0 is equipped with weapon 1, it returns true. If member 0 is equipped with anything else, nor nothing at all, it returns false. 


Again, if there is an easier way to do this, please let me know! If I'm on the right track, but just need tweaks, let me know as well.


I should probably note that I am using Yanfly's EquipCore. 


Thanks again for your help!
Try using the weapons() and armors() methods. They return arrays of equipped weapons/armors for a given party member. Sum the length properties and you're good to go.


Here's an example for a function that returns the sum of weapons equipped.

Code:
function partyWeaponCount() {
    return $gameParty.members().reduce(function (sum, member) {
        return sum += member.weapons().length;
    }, 0);
}
Try using the weapon() and armors() methods. They return arrays of equipped weapons/armors for a given party member. Sum the length properties and you're good to go.


Here's an example for a function that returns the sum of weapons equipped.



function partyWeaponCount() {
return $gameParty.members().reduce(function (sum, member) {
return sum += member.weapons().length;
}, 0);
}





Thank you so much! This is working perfectly! I really really appreciate your help! 

Original thread: https://forums.rpgmakerweb.com/threads/counting-equipped-weapons-and-armors.72220/