sort the list
<input id="atnbg20170212su1708" /><a href="javascript:atnbg20170212su1708()" style="color:pink">sort the list</a><div id="atnbg20170212su1708sorted" style="color:burlywood"></div>
<script>
function atnbg20170212su1708() {
var thelist = document.getElementById("atnbg20170212su1708")
var thepartlysortedlist = thelist.value
var thesortedlist = ""
function findthenexturl(thepartlysortedlist) {
var thepartlysortedarray = thepartlysortedlist.split(",")
var thenexturl = thepartlysortedarray[0]
function symbol(url) {return url.split("/")[url.split("/").length - 1].split("c")[0]}
for (var i = 0; i < thepartlysortedarray.length; i = i + 1) {
var thisurl = thepartlysortedarray[i]
if (symbol(thisurl) < symbol(thenexturl)) {thenexturl = thisurl}}
return thenexturl}
function removetheurl(thepartlysortedlist,theurl) {
var thepartlysortedarray = thepartlysortedlist.split(",")
var thereplacementlist = ""
for (var i = 0; i < thepartlysortedarray.length; i = i + 1) {
var thisurl = thepartlysortedarray[i]
if (thisurl != theurl) {
thereplacementlist = thereplacementlist + thisurl
if (i < thepartlysortedarray.length - 1) {thereplacementlist = thereplacementlist + ","}}}
return thereplacementlist}
for (var i = 0; i < thelist.length; i = i + 1) {
var thenexturl = findthenexturl(thepartlysortedlist)
thesortedlist = thesortedlist + thenexturl
var thepartlysortedarray = thepartlysortedlist.split(",")
if (i < thepartlysortedarray.length - 1) {thesortedlist = thesortedlist + ","}
thepartlysortedlist = removetheurl(thepartlysortedlist,thenexturl)}
document.getElementById("atnbg20170212su1708sorted").innerHTML = thesortedlist
}
</script>
No comments:
Post a Comment