Note that there are some explanatory texts on larger screens.

plurals
  1. POoptimize js script and find the best solution
    primarykey
    data
    text
    <p>i need to optimize this script by any way, may be you can find better algorithm for this sorting. this script get points like "Oslo - Tokyo, Moscow - Berlin, Rome - Barselona, Barselona - Oslo, Tokyo - Moscow, Berlin - New-York" and sort it. you can see it in this page <a href="http://at-no.ru/sorting.html" rel="nofollow">http://at-no.ru/sorting.html</a> - first is place of department, second is place of arrival, third and four does not matter. first button is "Add card" and second is "Sort cards". you can fill it in english. travel can't finish at the start point - in that case script will be looping and freezes.</p> <pre><code>function sortCards(arr) { // card's sorting var map = {}; // create map for (var i=0; i&lt;arr.length; i++) { map[arr[i].from] = arr[i]; // fill map for each card } for (var from in map) { map[from].next = map[map[from].to]; // create linked list } for (var from in map) { for (var next = map[from]; next; next = next.next) { delete map[next.to]; // find start point } var start = from; // put from to var start } var arr = []; for (var point = map[start]; point; point = point.next) { arr.push(point); // fill array } for (var i=0; i&lt;arr.length; i++) { var result = document.createElement("div"); document.getElementById('entered').appendChild(result).innerHTML='&lt;center&gt;' + 'Get ' + arr[i].transport + ' from ' + arr[i].from + ' to ' + arr[i].to + '. Place ' + arr[i].seat + '&lt;br&gt;' + '&lt;/center&gt;'; // display the result } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload