Nodejs Array Same sameElementCount(arr)

Here you can find the source of sameElementCount(arr)

Method Source Code

Array.prototype.sameElementCount = function(arr) {
   var result = [], count = null;
   arr.sort();/*from www .  j a  v a  2 s  .  c  om*/
   for (var i = 0; i < arr.length;) {
      count = 1;
      for (var j = i + 1; j < arr.length; j++) {
         if (arr[i] == arr[j]) {
            count++;
         }
      }
      result.push([ arr[i], count ]);
      i += count;
   }
   return result;
};

Related

  1. same()
    Array.prototype.same = function() {
        for(var i = 1; i < this.length; i++) {
            if(this[i] !== this[0])
                return false;
        return true;
    
  2. same(comparisons, unordered)
    Array.prototype.same = function(comparisons, unordered) {
        if (Object.prototype.toString.call(this) !== '[object Array]') {
            throw new TypeError("`this` must be Array, not " + typeof this);
        var arglen = arguments.length;
        if (arglen < 1) {
            throw new TypeError("`arguments` must have at least one comparison `Array`");
        var firstarg = arguments[0];
    ...
    
  3. same(obj)
    Array.prototype.same = function(obj) { 
        var i = this.length;
        while (i--) {
            if (obj.contains(this[i])) {
        return false;
    };
    
  4. same_values(arr)
    function findMissing(arr1, arr2){
      if((arr1.length) && (arr2.length) === 0){
        return 0;
      if(arr1.same_values(arr2)){
        return 0;
      for(num = 0; num < arr2.length; num++){
        if(isInArray(arr2[num], arr1) !== true) return arr2[num];
    ...