I am having trouble understanding the order in which stuff is executed in javascript... It seems like it completely does not follow the order I am accustomed with from Java. Could anyone suggest on how to force right order?
I want the getRegisteredUsersList to complete first, which will provide the get AllUsersActivityCount with first argument, which is an array.
Then for each element of that array I want the getAllUsersActivityCount to perform countActivitiesForUser on it. Unfortunately this does not work as expected.
I have the following methods:
$scope.count = function(){
  var result = getAllUsersActivityCount(getRegisteredUsersList(),4);
  return result;
};
getRegisteredUsersList = function(){
  var url = "MY QUERY URL THAT RETURNS ARRAY OF USERS";
   $http.get(url).success(
     function(data, status, headers, config) {
       return data;
     }
   );
};
getAllUsersActivityCount = function(usersList,type){
  var sdf = new JsSimpleDateFormat("MMM d, yyyy");
  var date = sdf.format(new Date());
  var returnArray = [];
  for(var i=0;i<usersList.length;i++){
    var userid= usersList[i].userid;
    var name= usersList[i].name;
    returnArray.push({userid: userid, name: name, count: countActivitiesForUser(userid,type,date)});
    }
  return returnArray;
};
$scope.countActivitiesForUser = function(userid,type,date){
  var url =     "MY QUERY URL THAT RETURNS SINGLE NUMBERICAL VALUE";
  $http.get(url).success(
    function(data, status, headers, config) {
      return data;
    }
    );
};
 
    