0

I have an HTML table that I'm storing task versions. The following examples of rows:

1.0   Task 1
1.1   Task 1.1
1.1.1 Task 1.1.1
1.1.2 Task 1.1.2
1.2.0 Task 1.2.0
1.2.1 Task 1.2.1

I want to be able to insert for example a new task after 1.1.1 so a new 1.1.2 will be added and the rest of the child values will increment:

1.0   Task 1
1.1   Task 1.1
1.1.1 Task 1.1.1
1.1.2 Task 1.1.2 - New entry
1.1.3 Task 1.1.3
1.2.0 Task 1.2.0
1.2.1 Task 1.2.1

I'm trying to figure out how to store this data in Javascript so I can easily add to or even delete anywhere in my structure.

Any ideas or suggestions?

Solution Using Maps

Just wanted to post after google trees and ran into maps

let map = new Map();

map.set('1.1.1', 'Task 1.1.1');
map.set('1.2.0', 'Task 1.2.0');
map.set('1.1', 'Task 1.1');
map.set('1.1.2', 'Task 1.1.2');
map.set('1.2.1', 'Task 1.2.1');
map.set('1.0', 'Task 1.0');

var mapAsc = new Map([...map.entries()].sort());

const elem = document.querySelector('#content');


let items = '';
for (let item of mapAsc.keys()) {
  items += item + '\r\n ';
}
elem.innerText = items; 

Output:

1.0
1.1
1.1.1
1.1.2
1.2.0
1.2.1

My JSFiddle enter link description here

adviner
  • 3,295
  • 10
  • 35
  • 64
  • What exactly have you tried to accomplish this? Stack Overflow is not the place to ask for a tutorial and any "ideas or suggestions" wouldn't be an answer to your question. I suggest reading [How to ask a good question](http://stackoverflow.com/help/how-to-ask) and [The perfect question](http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/). Then try to work something out and if you get stuck, ask about it on SO. – icecub Jul 29 '19 at 01:25
  • Well, I haven't tried anything since I'm not quite sure where to start.I'm not asking for a solution but maybe a suggestion on what to look for so I can do more research. I would put examples but like I said I'm not sure where to start on this – adviner Jul 29 '19 at 01:32
  • I understand that, but this is not the place to ask such questions. No one is able to truely answer it unless they write you fully functional code and half a book explaining the entire process. That's way too broad for the website. "Answering" some tips or sugestions would never be a real answer. You could never be objective about the "best answer". Do you see the issues now? It's not like we're not willing to help you out. Of course we want to! It's just not possible within SO's rules and guidelines. – icecub Jul 29 '19 at 01:38
  • OK Thanks, I will look it up – adviner Jul 29 '19 at 01:40
  • 1
    And ye, as for a tip, you might want to check out this old question on SO: https://stackoverflow.com/questions/6832596/how-to-compare-software-version-number-using-js-only-number It's about version comparison, but most of the code in the accepted answer will be very usefull for you to accomplish your goal. – icecub Jul 29 '19 at 01:48
  • Thanks look like a good starting point for me – adviner Jul 29 '19 at 01:51

0 Answers0