Compare elements within 2 strings (character 1, character 2, delimiter optional)
Files: diff.js
Example usage/*var str1 = "Tie, Mao,"; var str2 = "Tie, Mao, csdn"; var result = diff (str1, str2, ', '); Object var rs = "" + result; "Csdn" var df1 = result.diff1; ["]var" DF2 = result.diff2; ["Csdn"]*///comparison of elements within 2 strings (character 1, character 2, delimiter optional) function diff (str1, str2, separator) {//str1 = str1 | | ""; str2 = str2 | | ""; Separator = Separator | | ",";//arr has ele element function haselement (arr, ele) {//memory loop var hasItem1 = False;for (var i2=0; i2 < arr.length; i2++) {//var I tem2 = Arr[i2] | | ""; if (!item2) {continue;} if (ele = = item2) {hasItem1 = True;break;}} return hasItem1;}; function Inanotb (A, B) {//In a, not in b var res = [];for (var i1=0; i1 < a.length; i1++) {var item1 = A[i1] | | ""; if (!item1) {continue;} var hasItem1 = haselement (b, Item1), if (!hasitem1) {Res.push (item1);}} Return res;};/ /var List1 = Str1.split (","), var list2 = Str2.split (",");//var diff1 = INANOTB (List1, list2); var diff2 = Inanotb (List2, Li ST1);//Returns the result var = {Diff1:diff1,diff2:diff2,separator:separator,tostring:functiOn () {//var res = this["diff1"].slice (0), res = Res.concat (this["diff2"]),//return res.join (this["separator"]);}};/ /return result;};
Please use as needed, I used to compare the exported tables in 2 Oracle databases with those not imported successfully.
JS comparison of the elements within 2 strings (character 1, character 2, delimiter optional)