I have an unsorted Array holding the following IDs:
@un_array = ['bar', 'para-3', 'para-2', 'para-7']
Is there a smart way of using Nokogiri (or plain Javascript) to sort the array according to the order of the IDs in the example HTML document below?
require 'rubygems'
require 'nokogiri'
value = Nokogiri::HTML.parse(<<-HTML_END)
"<html>
<head>
</head>
<body>
<p id='para-1'>A</p>
<div id='foo'>
<p id='para-2'>B</p>
<p id='para-3'>C</p>
<div id='bar'>
<p id='para-4'>D</p>
<p id='para-5'>E</p>
<p id='para-6'>F</p>
</div>
<p id='para-7'>G</p>
</div>
<p id='para-8'>H</p>
</body>
</html>"
HTML_END
In this case the resulting, sorted array should be:
['para-2', 'para-3', 'bar', 'para-7']