Background updated algorithm, used to mine data, the front desk (i) with the background to build a new page, lasted two weeks, from 0 to now the joint, whistling, tired, but more is the joy of completing work.
Not much nonsense said, in the process encountered an interface need to transfer two-dimensional array, is about the selection of sentences, and then the document number and sentence number is spliced into the array, and then pressed into the large arrays to send to the background to save the data.
When the foreground is stored, the selected sentence stores its document number directly, so that the underlying stored array becomes an array of objects:
arr = [ {name:***,docnum:0,linenum:3}, {name:***,docnum:2,linenum:1}, {name: ***,docnum:3,linenum:2}, {name:***,docnum:0,linenum:1}, {name:***,docnum:3, Linenum:2}, {name:***,docnum:2,linenum:3},]
The interface requirements form is:
arr = [ [0,2,3], [1,1,2,3]]
The first element of the Subarray represents the document number, followed by the sentence number.
In this pit of the loop for a long time ...
Finally think of the characteristics of the object's properties only to find the simple:
//loops through the array of objects into this$scope. List = [ [The], [0,2], [1,3], [0,1], [1,4],]//then go to the weight, use the attributes of the object, save the document number to the property name, and the line number to its valuevarDocnumobj ={}angular.foreach ($scope. List,function(obj, i) {if(!docnumobj[obj[0]]) {docnumobj[obj[0]] = obj[1].tostring (); } Else{docnumobj[obj[0]] + = obj[1].tostring (); }}) Console.log (docnumobj);//And then iterate over the object properties, the puzzle arrayvarFinalarr = []; for(varIinchdocnumobj) {Console.log (i); varCharsarr = Docnumobj[i].split ("); Charsarr.unshift (i); Finalarr.push (Charsarr);} Console.log (Finalarr);
This is still very simple!
In a two-dimensional array, the first element value of the sub-array is re-