Last active
August 29, 2015 14:01
-
-
Save ipedrazas/9350b51c58d494ac21ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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