Monday, March 13, 2017

new next() plus pattern matching q

function next() { // first we need to get var thecurrentlistnote = document.getElementById("sns20170311sa1558thecurrentlistnote") var thecurrentlistnotearray = thecurrentlistnote.innerHTML.split(" ") var thecurrentlisttype = thecurrentlistarray[0] thecurrentlistnotearray.shift() var thepatterntomatch = thecurrentlistnotearray.join(" ") var thecurrentlist = document.getElementById("sns20170311sa1558" + thecurrentlisttype) var thelistpositionnote = document.getElementById("sns20170311sa1558the" + thecurrentlisttype + "position") var thelistingpositionnote = document.getElementById("sns20170311sa1558the" + thecurrentlisttype + "listingposition") if (thelistpositionnote.innerHTML === "body") {simplenext(thelistpositionnote,thecurrentlist,thecurrentlistingnote)} else {searchnext(thelistpositionnote,thecurrentlist,thepatterntomatch)}} function simplenext(thelistpositionnote,thecurrentlist,thecurrentlistingnote,thelistingpositionnote) { var thelistposition = parseInt(thelistpositionnote.innerHTML) var thecurrentlistingnumber = parseInt(thecurrentlistingnote.innerHTML) thecurrentlistingnote.innerHTML = thecurrentlistingnumber + 1 var thecurrentlisting = thecurrentlist.split("
")[parseInt(thecurrentlistingnote.innerHTML)] if (thecurrentlisting.split(" ")[0][0] != "h") { thelistingpositionnote.innerHTML = "end"} getachart()} function searchnext(thelistpositionnote,thecurrentlist,thepatterntomatch,thelistingpositionnote) { var thelistarray = thecurrentlist.innerHTML.split("
") var thecurrentlisting = parseInt(thecurrentlistingnote.innerHTML) for (var i = thecurrentlisting + 1; i < thelistarray.length; i = i + 1) { var thelistingarray = thelistarray[i].split(" ") var thepattern = thelistingarray.shift().join(" ") if (matchthepattern(thepattern,thepatterntomatch) === "matches") { thelistpositionnote.innerHTML = i thelistingpositionnote.innerHTML = "body" getachart() return}}} var matchq = matchthepattern we now need a pattern matching function function matchthepattern(thepattern,thepatterntomatch) { it's a whole new problem! returns either "matches" or "does not match" if the listing array starts with a symbol then shift() once to get the pattern if the listing array no

No comments:

Post a Comment