title: Troubleshooting a code that is supposed to display 1 if Mean = Mode and 0 if it does not
body: <p>I am a novice coder and I am trying to write a code that returns 1 if the mean is equal to the mode and 0 if it is not. So far the code I have written is only returning 0, even if it is supposed to be 1. Any help or tips in pin pointing where I went wrong will be greatly appreciated!</p>
  <pre><code>function ArrayChallenge(arr) { 
  let sum = 0
  let totalNum = arr.length
  let mean = sum/totalNum
  for (i=0; i &lt; arr.length; i++) {
    if (arr[i] &gt; 0) {
      sum+= arr[i]
    }
  }
  
  const numList = {}
  arr.forEach(elem =&gt; numList[elem] = numList[elem] + 1 || 1)
  let mode = []
  let numMax = 0
  for (const key in numList) {
    if(numList[key] &gt; numMax) {
      mode = [Number(key)]
      numMax = numList[key]
    } else if (numList[key] === numMax) {
      mode.push(Number(key))
    }
  }
  if (mode.length === Object.keys(numList). length) mode = []
  if (mean === mode) {
    return 1
  } else return 0
  } 
  </code></pre>