Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  <p>Open the console to see the output</p>
  <script>
    (function() {
      test([1, 2, 0, 1, 1, 1]);
      test([1, 1, 1, 1, 1, 1]);
      function test(a) {
        var count = countUniques(a);
        console.log("Array = " + a.join() + ", count = " + count);
      }
      function countUniques(a) {
          var valuesSeen = {};
          var count = 0;
      
          a.forEach(function(value) {
              if (!valuesSeen[value]) {
                  ++count;
                  valuesSeen[value] = true;
              }
          });
          return count;
      }
    })();
  </script>
</body>
</html>
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers