Index value is not recognized in RestAngular

When I fire an rest API call in an iteration then index value is not recognized inside the block. Refer code snippet: $scope.user = []; var userList = [{'id':1, 'name':'Joe'}, {'id':2, 'name': 'Jack'}]; for (var i=0; i<userList.length; i++) { R...
more »

2017-10-27 14:10 (1) Answers

Python 3 - Counting up with two different values

I am trying to figure out how to count up to a certain integer (as a range) alternating between two different numbers like 2 and 3. So that the output would be 2 5 7 10 12 15 etc. I started off trying to alter a simple while loop like the following ...
more »

2017-10-13 14:10 (10) Answers

jQuery has() not working as intended

Maybe I'm understanding it wrong but shouldn't this has() work in this situation? What am I doing wrong? $("#count").on("click", function(){ $(".item").each(function( index, element ){ $(element).text( index + 1 ); /*** this line ...
more »

2017-10-05 19:10 (1) Answers

Iterative search using Prolog solve(P) :- start(Start), search(Start,[Start],Q), reverse(Q,P). search(S,P,P) :- goal(S), !. /* done */ search(S,Visited,P) :- next_state(S,Nxt), /* generate next state */ ...
more »

2017-09-05 20:09 (0) Answers

How to iterate over this n-dimensional dataset?

I have a dataset which has 4 dimensions (for now...) and I need to iterate over it. To access a value in the dataset, I do this: value = dataset[i,j,k,l] Now, I can get the shape for the dataset: shape = [4,5,2,6] The values in shape represent...
more »

2017-08-17 16:08 (1) Answers

Finding a true integer square root from an array

I'm sure this is such a simple solution and for that I'm sorry but it's driving me mad. I'm trying to iterate over an array and find a true integer square root and if there isn't one then square the number instead. I don't know how to do Math.sqrt...
more »

2017-07-16 21:07 (5) Answers

Searching in python dictionary of dictionaries

I have a dictionary of dictionary called data_dict. Following is how it looks: {'UMANOFF ADAM S': {'total_stock_value': 'NaN', 'loans': 'NaN', 'salary': 288589}, 'YEAP SOON': {'total_stock_value': 192758, 'loans': 'NaN', 'salary': 'NaN'}, 'PIPER GRE...
more »

2017-05-04 13:05 (2) Answers

Efficiently sum items by type

I have a list of items with properties "Type" and "Time" that I want to quickly sum the time for each "Type" and append to another list. The list looks like this: Items = [{'Name': A, 'Type': 'Run', 'Time': 5}, {'Name': B, 'Type': 'Walk'...
more »

2017-04-12 20:04 (8) Answers

Non-iterative algorithm for 1D game of life

Consider a Boolean array a[n], where each element is a cell. A cell becomes alive (set to true) in the next generation if one and only one adjacent cell is alive, otherwise it becomes dead (set to false). The first and last cell are considered neighb...
more »

2017-02-19 03:02 (3) Answers

C++: Fast structure with two related keys

I have a situation where I have a container which needs to hold an ID (IDs are unique) and a data value. I also need to keep these IDs in an order. The tuple of these variables will be looked up by the ID, but then processed in order up to the found ...
more »

2016-12-06 15:12 (3) Answers

Recursion to loop

I've been given an assignment of writing both recurring and iterating programs of function, defined as: T(n,0)=n, n>=0 T(0,m)=m, m>=0 T(n,m)=T(n-1,m)+2*T(n, m-1) I am allowed to use only basic operations (so +, -, *, /, %) and not allowed...
more »

2016-12-06 03:12 (1) Answers

Iterating array over array without duplicates

I am writing a simple game with a simple collision detection system. I currently have this code for iterating the array over the same array so i can check if the objects are close to each other and if they will collide: var objects = []; //assu...
more »

2016-11-01 17:11 (2) Answers