# Finding the mode of an array

**URL:** <https://forum.kirupa.com/t/finding-the-mode-of-an-array/189792>\
**Category:** Uncategorized\
**Created:** [June 6, 2006, 10:10am UTC](https://forum.kirupa.com/t/finding-the-mode-of-an-array/189792 "2006-06-06T10:10:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Project004](https://avatars.discourse-cdn.com/v4/letter/p/ce7236/32.png) [@Project004](https://forum.kirupa.com/u/Project004)\
**Post date:** [June 6, 2006, 10:10am UTC](https://forum.kirupa.com/t/finding-the-mode-of-an-array/189792/1 "2006-06-06T10:10:03Z")

</div>

I have a simple array and I want to find the most common element in the array, i.e. the mode statistically

Can anyone help?

This is what I have so far,

var answers = [“c”,“b”,“c”,“a”,“b”,“c”,“a”,“b”];  
var aTotal = 0;  
var bTotal = 0;  
var cTotal = 0;  
for (i=0; i\<=answers.length; i++) {  
switch (answers\*) {  
case “a” :  
aTotal++;  
break;  
case “b” :  
bTotal++;  
break;  
case “c” :  
cTotal++;  
break;  
default :  
doNothing();  
}  
}

stop();

---

<div class="post-metadata">

**Author:** ![Project004](https://avatars.discourse-cdn.com/v4/letter/p/ce7236/32.png) [@Project004](https://forum.kirupa.com/u/Project004)\
**Post date:** [June 6, 2006, 6:17pm UTC](https://forum.kirupa.com/t/finding-the-mode-of-an-array/189792/2 "2006-06-06T18:17:04Z")

</div>

this has worked very well, thanks I have incorporated it with commemnts today  
i just had to swap the elements around to bias the results, which turned out to be just what i wanted to do (call me a hustler grin) regards the Project
