/ Published in: JavaScript
more alpha code, some abstractions
Expand |
Embed | Plain Text
//Todo: persistent link to a permalink :) //make a directory of tags by frequency function sortByFrequencyII () { var tagsByFQ = {}; var tagCount = []; var sortedTagsByFQ = {}; //make a object whose keys are frequencies and whose values are lists of tag names for (var name in tags) { var count = tags[name].frequency; //acc.push([name, tags[name].frequency]); (typeof tagsByFQ[count] == 'object' ? tagsByFQ[count].push(name) : tagsByFQ[count] = [name]); } //sort the lists of tag names for (var frequency in tagsByFQ) { tagsByFQ[frequency].sort(); tagCount.push(+frequency); } //sort the keys of the object by frequency tagCount.sort(asNumbers).reverse(); for (var index=0; index< tagCount.length; index++){ sortedTagsByFQ[tagCount[index]] = tagsByFQ[tagCount[index]]; } return sortedTagsByFQ; } showFQ(sortByFrequencyII()); function asNumbers (a,b) { return (a-b); } //frequency clouds function showFQ (tagsByFQ) { var html = ''; for (var count in tagsByFQ) { html += '<br/><h3 style="display: inline; padding-right: 1em;">'+count+'</h3>'; html += makeCloud(tagsByFQ[count]); } publishCloud(html); } function publishCloud (string) { document.getElementById('display').innerHTML = string; activateCloud(); } function makeCloud (list) { var html = ''; for (var i=0; i< list.length; i++) { var tag = list[i]; html += cloudLink(tag); //cloudlink should be able to also print the related tags in the title, not the count } return html; }
You need to login to post a comment.
