JSFiddle - React, Tailwind, and code Playground
JavaScript
Object.prototype.GetHashCode = function () {
var s = this instanceof Object ? stringify(this) : this.toString();
var hash = 0;
if (s.length === 0) return hash;
for (var i = 0; i < s.length; ++i) {
hash = ((hash << 5) - hash) + s.charCodeAt(i);
}
return hash;
};
Number.prototype.GetHashCode = function () { return this.valueOf(); };
function isPlainObject(obj)
{
if (
(typeof (obj) !== "object" || obj.nodeType || (obj instanceof Window))
||
(obj.constructor && !({}).hasOwnProperty.call(obj.constructor.prototype, "isPrototypeOf"))
)
{
return false;
}
return true;
}
function stringify(obj, s)
{
s = s || "";
for (var i in obj)
{
var o = obj[i];
if (o && (o instanceof Array || isPlainObject(o)))
{
s += i + ":" + JSON.stringify(o);
}
else if (o && typeof o === "object")
{
s += i + ":" + "$ref#" + o;
}
else
{
s += i + ":" + o;
}
}
return s;
}
function GroupByToArray(a, keySelector, elementSelector, comparer)
{
elementSelector = elementSelector || function(e) { return e; };
comparer = comparer ||
{
Equals: function(a,b) { return a==b },
GetHashCode: function(e) { return e.GetHashCode(); }
};
var key, hashKey, reHashKey;
var hashs = {};
for (var i = 0, n = a.length; i < n; ++i)
{
reHashKey = undefined;
key = keySelector(a[i]);
hashKey = comparer.GetHashCode(key);
if (typeof hashs[hashKey] !== "undefined")
reHashKey = comparer.Equals(key, hashs[hashKey].Key) ? hashKey : hashKey + " " + i;
if (typeof reHashKey !== "undefined" && reHashKey !== hashKey)
hashKey = reHashKey;
hashs[hashKey] = hashs[hashKey] || { Key: key, Elements: [] };
...