iteration

Looping through a JSON file

廉价感情. 提交于 2020-01-17 08:17:57
问题 As the title says I'm trying to read a JSON file that looks like the following: { "response": { "current_time": 1490040712, "success": 1, "items": { "AK-47 | Black Laminate (Minimal Wear)": { "last_updated": 1490025658, "value": 985, "quantity": 124 }, "AK-47 | Aquamarine Revenge (Field-Tested)": { "last_updated": 1490025658, "value": 1775, "quantity": 127 }, "AK-47 | Black Laminate (Field-Tested)": { "last_updated": 1490025658, "value": 890, "quantity": 130 }, "AK-47 | Aquamarine Revenge

Looping through a JSON file

夙愿已清 提交于 2020-01-17 08:17:07
问题 As the title says I'm trying to read a JSON file that looks like the following: { "response": { "current_time": 1490040712, "success": 1, "items": { "AK-47 | Black Laminate (Minimal Wear)": { "last_updated": 1490025658, "value": 985, "quantity": 124 }, "AK-47 | Aquamarine Revenge (Field-Tested)": { "last_updated": 1490025658, "value": 1775, "quantity": 127 }, "AK-47 | Black Laminate (Field-Tested)": { "last_updated": 1490025658, "value": 890, "quantity": 130 }, "AK-47 | Aquamarine Revenge

For loop within for loop with OR

大憨熊 提交于 2020-01-16 05:26:05
问题 I'm a bit stuck. I want to return my posts and my followed_users posts. I have a association called "followed_users" so I am able to call @user.followed_users <% for friends in current_user.followed_users %> <% for post in friends.posts %> <%= post.body %> <% end %> <% end %> This works, however only for "followed_users" posts. I also want to include my posts. So my plan is first check for my post then loop through all to see which belongs to my followed_users. My implementation is returning

loop through subArray as $key => $value in PHP

谁说胖子不能爱 提交于 2020-01-16 01:53:31
问题 given this data structure : array(2) { [0] array(7) { ["model_id"] 218 ["total"] 10 ["brand"] "This Brand" ["model_name"] "This Name" ["picture"] "this pic.jpg" ["color"] "Black" ["sizes"] array(3) { ["4"] "10 %" ["5"] "80 %" ["6"] "10 %" } } [1] array(7) { ["model_id"] 219 ["total"] 10 ["brand"] "This Brand" ["model_name"] "ThatName" ["picture"] "that pic.jpg" ["color"] "Black" ["sizes"] array(3) { ["4"] "20 %" ["5"] "50 %" ["6"] "30 %" } } } How can you loop into sizes as $key => $value ?

consolidate successive translations in D3

和自甴很熟 提交于 2020-01-15 12:26:14
问题 The following toy code (jsfiddle here) write to the console log translate(20,0) translate(20,0) translate(20,0) translate(20,0) translate(20,0) . Is it possible to get translate(100,0) as a "consolidated" translation? var svg = d3.select('svg'); var rec=svg.append("rect") .attr("width",20) .attr("height", 20) .attr("x", 0) .attr("y", 20) .attr("fill","#00ffff") .attr("transform","") ; for (var i=0;i<10;i++) { rec .attr("transform",rec.attr("transform")+" translate(20,0)") ; } console.log(rec

consolidate successive translations in D3

丶灬走出姿态 提交于 2020-01-15 12:26:07
问题 The following toy code (jsfiddle here) write to the console log translate(20,0) translate(20,0) translate(20,0) translate(20,0) translate(20,0) . Is it possible to get translate(100,0) as a "consolidated" translation? var svg = d3.select('svg'); var rec=svg.append("rect") .attr("width",20) .attr("height", 20) .attr("x", 0) .attr("y", 20) .attr("fill","#00ffff") .attr("transform","") ; for (var i=0;i<10;i++) { rec .attr("transform",rec.attr("transform")+" translate(20,0)") ; } console.log(rec

Match arguments to first argument

醉酒当歌 提交于 2020-01-15 09:26:34
问题 Okay I have to write a program that accepts 2 or more arguments and searches the second and remaining arguments for a matching argument. for example the output would be: ./a 3 h 4 9 3 3 found or ./a hsi and iash me 34 hsi hsi found So far I have this, and I'm pretty sure I've got a lot of junk in here that is useless in the situation. Any help provided would be greatly appreciated!: int linear_search (const char*A[], char*x, int v ){ int i; i = 0; while ( i < v - 1){ if (A[i] == x){ return 1;

Match arguments to first argument

自闭症网瘾萝莉.ら 提交于 2020-01-15 09:26:28
问题 Okay I have to write a program that accepts 2 or more arguments and searches the second and remaining arguments for a matching argument. for example the output would be: ./a 3 h 4 9 3 3 found or ./a hsi and iash me 34 hsi hsi found So far I have this, and I'm pretty sure I've got a lot of junk in here that is useless in the situation. Any help provided would be greatly appreciated!: int linear_search (const char*A[], char*x, int v ){ int i; i = 0; while ( i < v - 1){ if (A[i] == x){ return 1;

Compute sum of series

怎甘沉沦 提交于 2020-01-15 05:56:07
问题 I need to compute the sum of this series I need the output this way: If n = 3; x = function_name(n) I need to get x = 11. If n = 5; x = function_name(n) I need to get x = 45 . I believe I need a for-loop to iterate; but am finding it difficult to iterate the increment value itself. 回答1: inc=2; sum=1; next=1; n=input('what is n?\n'); for i=2:n next=next+inc; sum=sum+next; inc=inc+2; end disp('sum is '); disp(sum); 回答2: I guess you want the sum of the cumsum of the differences d of the numbers:

How can i create a new column that inserts the cell value of grouped column 'ID' (in time) when 'interaction' is 1

谁都会走 提交于 2020-01-15 03:16:28
问题 I have three relevant columns: time, id, and interaction. How can i create a new column with the id values that have a '1' in column 'interaction' in the given time window? Should look something like this: time id vec_len quadrant interaction Paired with 1 3271 0.9 7 0 1 3229 0.1 0 0 1 4228 0.5 0 0 1 2778 -0.3 5 0 2 4228 0.2 0 0 2 3271 0.1 6 0 2 3229 -0.7 5 1 [2778, 4228] 2 3229 -0.3 2 0 2 4228 -0.8 5 1 [2778, 3229] 2 2778 -0.6 5 1 [4228, 3229] 3 4228 0.2 0 0 3 3271 0.1 6 0 3 4228 -0.7 5 1