JavaScript Detecting how many different types of values in in an array

I know I could use variations of this answer to find out how many different types of data there are in an array:

How to count the number of certain element in an array?

But, what I am looking for is whether there is a simple way to count how many different types of data there are in an array:

I have arrays which may have 0, 1, or 2 as values

so it could be:

a = [1,2,0,1,1,1];

or they may all be the same and a different length:

a = [1,1,1,1,1,1,1,1,1,1,1,1,1];

In javascript, I would like a function that returns "1" if all values are the same, "2" if there is a mixture of just two of the possible values, and if the array contains all three values, "3".

Any help appreciated. Thanks.

Answer:1

I am trying to create a simple WebSocket connection in JavaScript against my Rails app. I get the following: WebSocket connection to 'ws://localhost:4000/' failed: Error during WebSocket handshake: ...

I am trying to create a simple WebSocket connection in JavaScript against my Rails app. I get the following: WebSocket connection to 'ws://localhost:4000/' failed: Error during WebSocket handshake: ...

  1. websocket with handshake
  2. websocket handshake in c
  3. websocket handshake for ssl
  4. websocket bad handshake with resp

Desired behavior - if you click anywhere on ".card" other than a "button", navigate to the link. I am not using window.location because I want users to be able to use their own discretion on whether ...

Desired behavior - if you click anywhere on ".card" other than a "button", navigate to the link. I am not using window.location because I want users to be able to use their own discretion on whether ...

I've got some code that sends an ajax request when a form is being submitted. This works the first time the form is submitted (it's a search module), but only once. I've added an effect to highlight ...

I've got some code that sends an ajax request when a form is being submitted. This works the first time the form is submitted (it's a search module), but only once. I've added an effect to highlight ...

  1. response from ajax call
  2. response from ajax
  3. response from ajax post
  4. return response from ajax call
  5. get response from ajax
  6. get response from ajax call jquery
  7. get response from ajax post
  8. get response from ajax call
  9. get response from ajax jquery
  10. download response from ajax
  11. get response from ajax request
  12. get response from ajax javascript
  13. return response from ajax
  14. ajax call without response
  15. get response from ajax call javascript
  16. no response from ajax jquery
  17. alert response from ajax
  18. response.redirect from ajax call
  19. json response from ajax call
  20. return response from ajax success

I'm replacing the smiley shortcuts from my text editor with img tags, but the logic I use also sees parts of links and tags as smiley shortcuts (e.g. :/ in http://, or :p in cursor:pointer in the ...

I'm replacing the smiley shortcuts from my text editor with img tags, but the logic I use also sees parts of links and tags as smiley shortcuts (e.g. :/ in http://, or :p in cursor:pointer in the ...