Skip to content

Instantly share code, notes, and snippets.

@ipedrazas
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ipedrazas/9350b51c58d494ac21ea to your computer and use it in GitHub Desktop.
Save ipedrazas/9350b51c58d494ac21ea to your computer and use it in GitHub Desktop.
/* Controllers */
angular.module('dotApp').controller('dotMarkController', ['$scope', 'api', '$routeParams', function ($scope, api, $routeParams) {
$scope.refreshEntries = function(){
api.getDotMarksEntries().success(function (data) {
var elems = new Array();
var etags = new Array();
_.each(data._items, function(item){
elems.push(item);
_.each(item.tags, function(tag) {
etags.push(tag.toLowerCase());
});
});
$scope.dotmarks = elems;
$scope.etags = etags;
});
};
$scope.refreshEntries();
}]);
function reduce(arr) {
var tags = [], a = [], b = [], prev;
arr.sort();
for ( var i = 0; i < arr.length; i++ ) {
if ( arr[i] !== prev ) {
a.push(arr[i]);
b.push(1);
} else {
b[b.length-1]++;
}
prev = arr[i];
}
for ( var i = 0; i < a.length; i++ ) {
tags.push({label: a[i], count: b[i]});
}
return tags
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment