In a two-dimensional array, the first element value of the sub-array is re-

Source: Internet
Author: User

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-

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.