JS function Eql,equal,equalp

Source: Internet
Author: User

It's great if you like the 3 functions of Common Lisp.

function eql (obj, other) {return obj = = = Other;}    function equal (obj, other, Equalp) {if (Equalp = = = void 0) {Equalp = false;}    var _tostring = function (value) {return Object.prototype.toString.call (value);};    var Emptyp = function (value) {return json.stringify (value). length = = 2? true:false;    };        function Equal (obj, other, Equalp) {var objtag = _tostring (obj);        var Othertag = _tostring (other);        var objecttag = ' [Object Object] ';        var arraytag = ' [Object Array] '; if (Objtag!== objecttag && objtag!== arraytag && othertag!== objecttag && othertag!== Arraytag  {if (Equalp && typeof obj = = = ' String ' && typeof other = = = ' String ') {return            (obj). tolocaleuppercase () = = = (other). toLocaleUpperCase ();        } return obj = = = Other; } if (Objtag!== Othertag) return false; The collection type is different if (Object.getownpropertynames (obj). Length!== Object.getownpropertynames (other). length) return false; The number of collection elements is not the same if (Emptyp (obj) && Emptyp (Other)) return true;        An empty collection of the same type, always equal.                For (var k-in obj) {if (K-in-Other) {//elements intersect var obj_value = obj[k];                var other_value = other[k];                var Obj_item_tag = _tostring (Obj_value);                var Other_item_tag = _tostring (Other_value); if (Obj_item_tag = = = Other_item_tag) {if (Obj_item_tag = = = Objecttag | | obj_item_tag = = Arraytag | | o Ther_item_tag = = = Objecttag | |                    Other_item_tag = = = Arraytag) {return Equal (Obj_value, Other_value, Equalp); } else {if (Obj_value = = = Other_value) {CONSOLE_1.L                        OG (' Done. ');                        } else {return false;        }            }} else {return false;            }} else {return false;    }} return true; } return Equal (obj, other, Equalp);} function Equalp (obj, other) {return equal (obj, other, true);}
Debugging
Import {log as L} from ' console '; function eql (Obj:any, other:any) {return obj = = = Other;} function equal (Obj:any, other:any, Equalp:boolean = False) {Const _tostring = (value:any): string = Object.pro    Totype.toString.call (value);    Const Emptyp = function (value:any) {return json.stringify (value). length = = = 2? true:false;        } function Equal (Obj:any, Other:any, Equalp:boolean): boolean {Let Objtag = _tostring (obj);        Let Othertag = _tostring (other);  Let Objecttag = ' [Object Object] ' let Arraytag = ' [Object Array] ' if (objtag!== objecttag && Objtag !== arraytag && othertag!== objecttag && othertag!== arraytag) {if (Equalp && typeo F obj = = = ' String ' && typeof other = = ' String ' {return (obj). tolocaleuppercase () = = = (other). ToL            Ocaleuppercase ();        } return obj = = = Other; } if (Objtag!== othertag) return false;//The collection type is different if (Object.getownpropertynames (obj). Length!== Object.getownpropertynames (other). length) return false; The number of collection elements is not the same if (Emptyp (obj) && Emptyp (Other)) return true;        An empty collection of the same type, always equal.                for (const K-in obj) {if (K-in-Other) {//elements intersect let Obj_value = Obj[k];                Let Other_value = Other[k];                Let Obj_item_tag = _tostring (Obj_value);                Let Other_item_tag = _tostring (Other_value); if (Obj_item_tag = = = Other_item_tag) {if (Obj_item_tag = = = Objecttag | | obj_item_tag = = Arraytag | | o Ther_item_tag = = = Objecttag | |                    Other_item_tag = = = Arraytag) {return Equal (Obj_value, Other_value, Equalp);                        } else {if (Obj_value = = = Other_value) {L (' done. ');                        } else {return false;             }                    }   } else {return false;            }} else {return false;    }} return true; } return Equal (obj, other, Equalp)}function Equalp (Obj:any, Other:any) {return Equal (obj, other, true);} L (Equalp (' Hello ', ' hello '))

JS function Eql,equal,equalp

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.