gw1500se Posted March 2, 2023 Share Posted March 2, 2023 (edited) I have an associative array A that contains, among other things, a key named "requestor". I have a second array B that also contains a key named "requestor". I need a count of the number of elements in array A, excluding "requestor" value matches with those in array B. It appears there is no built in function that can help with that so I am wanting to confirm that a brute force loop is the only way. Edited March 2, 2023 by gw1500se Quote Link to comment Share on other sites More sharing options...
Barand Posted March 2, 2023 Share Posted March 2, 2023 What have you tried so far? Quote Link to comment Share on other sites More sharing options...
gw1500se Posted March 2, 2023 Author Share Posted March 2, 2023 Reading about "count" and I looking at examples. Quote Link to comment Share on other sites More sharing options...
Barand Posted March 2, 2023 Share Posted March 2, 2023 I was hoping for code and examples of your input arrays. Quote Link to comment Share on other sites More sharing options...
gw1500se Posted March 2, 2023 Author Share Posted March 2, 2023 I haven't written any code to do that because I don't know where to start but here is an example of my arrays: Array A (note the key to match is requesters): json_array={ filters:[ { requester: document.getElementById("requester").checked, title: document.getElementById("title").checked, none: document.getElementById("none").checked } ], requesters:[ ], titles:[ ], excludes:[ ], delay: 1, amount: 0.00 }; Array B (note the matching key is requester_name): { "tasks":[ { "task_id":"3ACRLU861YXPXVRHNPV5UASKVTYEBP", "assignment_id":"3EFVCAY5LFSHTXDWOGRNP7A1RQF8JJ", "accepted_at":"2023-03-02T17:52:40.000Z", "deadline":"2023-03-02T18:00:40.000Z", "time_to_deadline_in_seconds":455, "state":"Assigned", "question":{ "value":"https://www.mturkcontent.com/dynamic/hit?assignmentId=3EFVCAY5LFSHTXDWOGRNP7A1RQF8JJ&hitId=3ACRLU861YXPXVRHNPV5UASKVTYEBP&workerId=AN4TEA6EBEB2V&turkSubmitTo=https%3A%2F%2Fwww.mturk.com", "type":"InternalURL", "attributes":{ "FrameSourceAttribute":"https://www.mturkcontent.com/dynamic/hit?assignmentId=3EFVCAY5LFSHTXDWOGRNP7A1RQF8JJ&hitId=3ACRLU861YXPXVRHNPV5UASKVTYEBP&workerId=AN4TEA6EBEB2V&turkSubmitTo=https%3A%2F%2Fwww.mturk.com", "FrameHeight":"0" } }, "project":{ "hit_set_id":"3U8PAUGKO8QE66VCCT4T6ZDTJTVCNH", "requester_id":"A210GEVDVU8V7E", "requester_name":"GHS Research", "title":"Give us your opinions", "description":"Please share your opinion to our customers new products and services.", "assignment_duration_in_seconds":480, "creation_time":"2023-03-02T06:19:42.000Z", "assignable_hits_count":2, "latest_expiration_time":"2023-03-09T06:19:42.000Z", "caller_meets_requirements":false, "caller_meets_preview_requirements":false, "last_updated_time":"2023-03-02T06:19:42.000Z", "monetary_reward":{ "currency_code":"USD", "amount_in_dollars":0.66 }, "hit_requirements":[ { "qualification_type_id":"00000000000000000071", "comparator":"EqualTo", "worker_action":"PreviewHit", "qualification_values":[ "US" ], "caller_meets_requirement":null, "qualification_type":{ "qualification_type_id":"00000000000000000071", "name":"Location", "visibility":true, "description":"The Location Qualification represents the location you specified with your mailing address. Some HITs may only be available to residents of particular countries, states, provinces or cities.", "has_test":false, "is_requestable":false, "keywords":"location" }, "caller_qualification_value":{ "integer_value":null, "locale_value":{ "country":null, "subdivision":null } } } ], "requester_url":"/requesters/A210GEVDVU8V7E/projects.json?ref=w_pl_prvw" }, "expired_task_action_url":"/projects/3U8PAUGKO8QE66VCCT4T6ZDTJTVCNH/tasks.json?ref=w_pl_prvw", "task_url":"/projects/3U8PAUGKO8QE66VCCT4T6ZDTJTVCNH/tasks/3ACRLU861YXPXVRHNPV5UASKVTYEBP.json?assignment_id=3EFVCAY5LFSHTXDWOGRNP7A1RQF8JJ&ref=w_pl_prvw" }, { "task_id":"334ZEL5JX8ZQPZFW1JDZD8ATID6SOA", "assignment_id":"3TE3O85733S33XO7PYKZ55XKP062R8", "accepted_at":"2023-03-02T17:52:26.000Z", "deadline":"2023-03-02T18:07:26.000Z", "time_to_deadline_in_seconds":861, "state":"Assigned", "question":{ "value":"https://video-recording-prod.trafficmanager.net?assignmentId=3TE3O85733S33XO7PYKZ55XKP062R8&hitId=334ZEL5JX8ZQPZFW1JDZD8ATID6SOA&workerId=AN4TEA6EBEB2V&turkSubmitTo=https%3A%2F%2Fwww.mturk.com", "type":"ExternalURL", "attributes":{ "FrameSourceAttribute":"https://video-recording-prod.trafficmanager.net?assignmentId=3TE3O85733S33XO7PYKZ55XKP062R8&hitId=334ZEL5JX8ZQPZFW1JDZD8ATID6SOA&workerId=AN4TEA6EBEB2V&turkSubmitTo=https%3A%2F%2Fwww.mturk.com", "FrameHeight":"0" } }, "project":{ "hit_set_id":"3R0WG3C6GDBDVVRJQ1HJTZUYBBMWLT", "requester_id":"A2SAUCU1B6BDTS", "requester_name":"IC3 AI team", "title":"Record a one minute video of yourself", "description":"Record a one minute video of yourself performing some simple actions.", "assignment_duration_in_seconds":900, "creation_time":"2023-02-21T22:41:30.000Z", "assignable_hits_count":1, "latest_expiration_time":"2023-03-07T22:41:30.000Z", "caller_meets_requirements":false, "caller_meets_preview_requirements":false, "last_updated_time":"2023-02-21T22:41:30.000Z", "monetary_reward":{ "currency_code":"USD", "amount_in_dollars":2.0 }, "hit_requirements":[ { "qualification_type_id":"00000000000000000071", "comparator":"NotIn", "worker_action":"AcceptHit", "qualification_values":[ "US-CA", "US-IL", "US-TX", "US-WA" ], "caller_meets_requirement":null, "qualification_type":{ "qualification_type_id":"00000000000000000071", "name":"Location", "visibility":true, "description":"The Location Qualification represents the location you specified with your mailing address. Some HITs may only be available to residents of particular countries, states, provinces or cities.", "has_test":false, "is_requestable":false, "keywords":"location" }, "caller_qualification_value":{ "integer_value":null, "locale_value":{ "country":null, "subdivision":null } } } ], "requester_url":"/requesters/A2SAUCU1B6BDTS/projects.json?ref=w_pl_prvw" }, "expired_task_action_url":"/projects/3R0WG3C6GDBDVVRJQ1HJTZUYBBMWLT/tasks.json?ref=w_pl_prvw", "task_url":"/projects/3R0WG3C6GDBDVVRJQ1HJTZUYBBMWLT/tasks/334ZEL5JX8ZQPZFW1JDZD8ATID6SOA.json?assignment_id=3TE3O85733S33XO7PYKZ55XKP062R8&ref=w_pl_prvw" }, { "task_id":"3SZYX62S6NFKMGAYGRFHF8HZW0275Z", "assignment_id":"3HWRJOOETDH9OHLD5XBX3DFYWBRSEH", "accepted_at":"2023-03-02T17:52:30.000Z", "deadline":"2023-03-02T18:22:30.000Z", "time_to_deadline_in_seconds":1765, "state":"Assigned", "question":{ "value":"https://app.cloudresearch.com/TakeLaunchedSurvey/Take/406247?assignmentId=3HWRJOOETDH9OHLD5XBX3DFYWBRSEH&hitId=3SZYX62S6NFKMGAYGRFHF8HZW0275Z&workerId=AN4TEA6EBEB2V&turkSubmitTo=https%3A%2F%2Fwww.mturk.com", "type":"ExternalURL", "attributes":{ "FrameSourceAttribute":"https://app.cloudresearch.com/TakeLaunchedSurvey/Take/406247?assignmentId=3HWRJOOETDH9OHLD5XBX3DFYWBRSEH&hitId=3SZYX62S6NFKMGAYGRFHF8HZW0275Z&workerId=AN4TEA6EBEB2V&turkSubmitTo=https%3A%2F%2Fwww.mturk.com", "FrameHeight":"0" } }, "project":{ "hit_set_id":"3K27O5FVC7L0HVAA64X4I72YJIHW59", "requester_id":"A3FKSNPXNIOOPM", "requester_name":"Aaron Shine", "title":"Quick psychology experiment (~ 6 minutes)", "description":"Study about choices", "assignment_duration_in_seconds":1800, "creation_time":"2023-02-28T13:25:41.000Z", "assignable_hits_count":18, "latest_expiration_time":"2023-03-30T13:25:41.000Z", "caller_meets_requirements":false, "caller_meets_preview_requirements":false, "last_updated_time":"2023-02-28T13:25:41.000Z", "monetary_reward":{ "currency_code":"USD", "amount_in_dollars":0.67 }, "hit_requirements":[ { "qualification_type_id":"3CE74LL4O7AZFGA0UGQGHW46O9VEKS", "comparator":"GreaterThanOrEqualTo", "worker_action":"ViewHitSet", "qualification_values":[ "100" ], "caller_meets_requirement":null, "qualification_type":{ "qualification_type_id":"3CE74LL4O7AZFGA0UGQGHW46O9VEKS", "name":"rhsnlk98", "visibility":true, "description":"rhsnlk98", "has_test":false, "is_requestable":true, "keywords":"" }, "caller_qualification_value":{ "integer_value":null, "locale_value":{ "country":null, "subdivision":null } } }, { "qualification_type_id":"3HWVT555HZH74TPJLQREQJ8UODNIAC", "comparator":"DoesNotExist", "worker_action":"PreviewHit", "qualification_values":[ ], "caller_meets_requirement":null, "qualification_type":{ "qualification_type_id":"3HWVT555HZH74TPJLQREQJ8UODNIAC", "name":"SurveyGroup [4908]", "visibility":true, "description":"Survey Group [4908]", "has_test":false, "is_requestable":true, "keywords":"" }, "caller_qualification_value":{ "integer_value":null, "locale_value":{ "country":null, "subdivision":null } } }, { "qualification_type_id":"00000000000000000040", "comparator":"GreaterThanOrEqualTo", "worker_action":"PreviewHit", "qualification_values":[ "1000" ], "caller_meets_requirement":null, "qualification_type":{ "qualification_type_id":"00000000000000000040", "name":"Total approved HITs", "visibility":true, "description":"This Qualification is generated automatically and reflects the number of HITs which you have submitted an answer that has been approved. Your score is a value greater than or equal to 0.", "has_test":false, "is_requestable":false, "keywords":"total,assignments,approved" }, "caller_qualification_value":{ "integer_value":null, "locale_value":{ "country":null, "subdivision":null } } }, { "qualification_type_id":"3QIZOA92R5544PHF4ZHUURTCSBJPBA", "comparator":"DoesNotExist", "worker_action":"PreviewHit", "qualification_values":[ ], "caller_meets_requirement":null, "qualification_type":{ "qualification_type_id":"3QIZOA92R5544PHF4ZHUURTCSBJPBA", "name":"Exc: [1594239018-406247]", "visibility":true, "description":"Excluded from HIT 406247", "has_test":false, "is_requestable":true, "keywords":"" }, "caller_qualification_value":{ "integer_value":null, "locale_value":{ "country":null, "subdivision":null } } }, { "qualification_type_id":"000000000000000000L0", "comparator":"GreaterThanOrEqualTo", "worker_action":"PreviewHit", "qualification_values":[ "99" ], "caller_meets_requirement":null, "qualification_type":{ "qualification_type_id":"000000000000000000L0", "name":"HIT approval rate (%)", "visibility":true, "description":"This Qualification is generated automatically and reflects the percentage of HITs for which you have submitted an answer that has been approved divided by the total number of HITs that have been approved or rejected. Your score is a value between 0 and 100. A score of 100 indicates that every HIT you have submitted has been approved.", "has_test":false, "is_requestable":false, "keywords":"percent,assignments,approved" }, "caller_qualification_value":{ "integer_value":null, "locale_value":{ "country":null, "subdivision":null } } }, { "qualification_type_id":"00000000000000000071", "comparator":"In", "worker_action":"PreviewHit", "qualification_values":[ "US" ], "caller_meets_requirement":null, "qualification_type":{ "qualification_type_id":"00000000000000000071", "name":"Location", "visibility":true, "description":"The Location Qualification represents the location you specified with your mailing address. Some HITs may only be available to residents of particular countries, states, provinces or cities.", "has_test":false, "is_requestable":false, "keywords":"location" }, "caller_qualification_value":{ "integer_value":null, "locale_value":{ "country":null, "subdivision":null } } } ], "requester_url":"/requesters/A3FKSNPXNIOOPM/projects.json?ref=w_pl_prvw" }, "expired_task_action_url":"/projects/3K27O5FVC7L0HVAA64X4I72YJIHW59/tasks.json?ref=w_pl_prvw", "task_url":"/projects/3K27O5FVC7L0HVAA64X4I72YJIHW59/tasks/3SZYX62S6NFKMGAYGRFHF8HZW0275Z.json?assignment_id=3HWRJOOETDH9OHLD5XBX3DFYWBRSEH&ref=w_pl_prvw" }, { "task_id":"3D5G8J4N5B6AICGVMTWIKG3NJTTTVK", "assignment_id":"3X73LLYYQ2GARHDLAAY4L01CLR4HNW", "accepted_at":"2023-03-02T17:52:39.000Z", "deadline":"2023-03-02T18:22:39.000Z", "time_to_deadline_in_seconds":1774, "state":"Assigned", "question":{ "value":"https://app.cloudresearch.com/TakeLaunchedSurvey/Take/404928?assignmentId=3X73LLYYQ2GARHDLAAY4L01CLR4HNW&hitId=3D5G8J4N5B6AICGVMTWIKG3NJTTTVK&workerId=AN4TEA6EBEB2V&turkSubmitTo=https%3A%2F%2Fwww.mturk.com", "type":"ExternalURL", "attributes":{ "FrameSourceAttribute":"https://app.cloudresearch.com/TakeLaunchedSurvey/Take/404928?assignmentId=3X73LLYYQ2GARHDLAAY4L01CLR4HNW&hitId=3D5G8J4N5B6AICGVMTWIKG3NJTTTVK&workerId=AN4TEA6EBEB2V&turkSubmitTo=https%3A%2F%2Fwww.mturk.com", "FrameHeight":"0" } }, "project":{ "hit_set_id":"34OVCINT39HEF9YHPEB2ZX9A2NQARP", "requester_id":"A2K56VOSUG3VNK", "requester_name":"Michael Greenstein", "title":"The Bus Crash Study(~ 5 minutes)", "description":"Purpose: We are conducting a research study to examine altruism which is the act of acting on the behalf of others, even at the possible expense of oneself (Kawamura & Kusumi, 2018).", "assignment_duration_in_seconds":1800, "creation_time":"2023-03-02T04:35:16.000Z", "assignable_hits_count":38, "latest_expiration_time":"2023-04-01T04:35:16.000Z", "caller_meets_requirements":false, "caller_meets_preview_requirements":false, "last_updated_time":"2023-03-02T04:35:16.000Z", "monetary_reward":{ "currency_code":"USD", "amount_in_dollars":0.5 }, "hit_requirements":[ { "qualification_type_id":"3HN7640Z3OXZSI55PKOD74VH889TSI", "comparator":"DoesNotExist", "worker_action":"PreviewHit", "qualification_values":[ ], "caller_meets_requirement":null, "qualification_type":{ "qualification_type_id":"3HN7640Z3OXZSI55PKOD74VH889TSI", "name":"0a3631f6", "visibility":true, "description":"TurkPrime Research Group", "has_test":false, "is_requestable":true, "keywords":"TurkPrime research group" }, "caller_qualification_value":{ "integer_value":null, "locale_value":{ "country":null, "subdivision":null } } }, { "qualification_type_id":"00000000000000000040", "comparator":"GreaterThanOrEqualTo", "worker_action":"PreviewHit", "qualification_values":[ "100" ], "caller_meets_requirement":null, "qualification_type":{ "qualification_type_id":"00000000000000000040", "name":"Total approved HITs", "visibility":true, "description":"This Qualification is generated automatically and reflects the number of HITs which you have submitted an answer that has been approved. Your score is a value greater than or equal to 0.", "has_test":false, "is_requestable":false, "keywords":"total,assignments,approved" }, "caller_qualification_value":{ "integer_value":null, "locale_value":{ "country":null, "subdivision":null } } }, { "qualification_type_id":"3ZA6RUP9VE6IG8F6WGLOG7AL08KQXY", "comparator":"DoesNotExist", "worker_action":"PreviewHit", "qualification_values":[ ], "caller_meets_requirement":null, "qualification_type":{ "qualification_type_id":"3ZA6RUP9VE6IG8F6WGLOG7AL08KQXY", "name":"Exc: [1090339537-404928]", "visibility":true, "description":"Excluded from HIT 404928", "has_test":false, "is_requestable":true, "keywords":"" }, "caller_qualification_value":{ "integer_value":null, "locale_value":{ "country":null, "subdivision":null } } }, { "qualification_type_id":"3CE74LL4O7AZFGA0UGQGHW46O9VEKS", "comparator":"GreaterThanOrEqualTo", "worker_action":"ViewHitSet", "qualification_values":[ "100" ], "caller_meets_requirement":null, "qualification_type":{ "qualification_type_id":"3CE74LL4O7AZFGA0UGQGHW46O9VEKS", "name":"rhsnlk98", "visibility":true, "description":"rhsnlk98", "has_test":false, "is_requestable":true, "keywords":"" }, "caller_qualification_value":{ "integer_value":null, "locale_value":{ "country":null, "subdivision":null } } }, { "qualification_type_id":"000000000000000000L0", "comparator":"GreaterThanOrEqualTo", "worker_action":"PreviewHit", "qualification_values":[ "90" ], "caller_meets_requirement":null, "qualification_type":{ "qualification_type_id":"000000000000000000L0", "name":"HIT approval rate (%)", "visibility":true, "description":"This Qualification is generated automatically and reflects the percentage of HITs for which you have submitted an answer that has been approved divided by the total number of HITs that have been approved or rejected. Your score is a value between 0 and 100. A score of 100 indicates that every HIT you have submitted has been approved.", "has_test":false, "is_requestable":false, "keywords":"percent,assignments,approved" }, "caller_qualification_value":{ "integer_value":null, "locale_value":{ "country":null, "subdivision":null } } }, { "qualification_type_id":"00000000000000000071", "comparator":"In", "worker_action":"PreviewHit", "qualification_values":[ "US" ], "caller_meets_requirement":null, "qualification_type":{ "qualification_type_id":"00000000000000000071", "name":"Location", "visibility":true, "description":"The Location Qualification represents the location you specified with your mailing address. Some HITs may only be available to residents of particular countries, states, provinces or cities.", "has_test":false, "is_requestable":false, "keywords":"location" }, "caller_qualification_value":{ "integer_value":null, "locale_value":{ "country":null, "subdivision":null } } } ], "requester_url":"/requesters/A2K56VOSUG3VNK/projects.json?ref=w_pl_prvw" }, "expired_task_action_url":"/projects/34OVCINT39HEF9YHPEB2ZX9A2NQARP/tasks.json?ref=w_pl_prvw", "task_url":"/projects/34OVCINT39HEF9YHPEB2ZX9A2NQARP/tasks/3D5G8J4N5B6AICGVMTWIKG3NJTTTVK.json?assignment_id=3X73LLYYQ2GARHDLAAY4L01CLR4HNW&ref=w_pl_prvw" }, { "task_id":"371DNNCG44VU3DLRUTAR4FZSY848TH", "assignment_id":"37UEWGM5HU12YIM8HL1ID97WDOJ1RH", "accepted_at":"2023-03-02T17:52:36.000Z", "deadline":"2023-03-02T18:32:36.000Z", "time_to_deadline_in_seconds":2371, "state":"Assigned", "question":{ "value":"https://app.cloudresearch.com/TakeLaunchedSurvey/Take/407052?assignmentId=37UEWGM5HU12YIM8HL1ID97WDOJ1RH&hitId=371DNNCG44VU3DLRUTAR4FZSY848TH&workerId=AN4TEA6EBEB2V&turkSubmitTo=https%3A%2F%2Fwww.mturk.com", "type":"ExternalURL", "attributes":{ "FrameSourceAttribute":"https://app.cloudresearch.com/TakeLaunchedSurvey/Take/407052?assignmentId=37UEWGM5HU12YIM8HL1ID97WDOJ1RH&hitId=371DNNCG44VU3DLRUTAR4FZSY848TH&workerId=AN4TEA6EBEB2V&turkSubmitTo=https%3A%2F%2Fwww.mturk.com", "FrameHeight":"0" } }, "project":{ "hit_set_id":"3TO8OQV8SS7AASYDA776PS0ORD5LOY", "requester_id":"A1165NJPZ7NRHY", "requester_name":"Betterment Labs", "title":"Gambling and Time (~ 20 minutes)", "description":"In this study, you will be asked to answer questions about your gambling and how you think about yourself in relation to your gambling behaviour. Phase II: At the end of this survey, we will ask for your permission to contact you for a brief follow-up survey in one month. If you would like to participate in the follow-up survey, you will receive a $1.00 bonus for approximately 10 minutes of your time.", "assignment_duration_in_seconds":2400, "creation_time":"2023-03-01T22:15:47.000Z", "assignable_hits_count":44, "latest_expiration_time":"2023-03-31T22:15:47.000Z", "caller_meets_requirements":false, "caller_meets_preview_requirements":false, "last_updated_time":"2023-03-01T22:15:47.000Z", "monetary_reward":{ "currency_code":"USD", "amount_in_dollars":1.0 }, "hit_requirements":[ { "qualification_type_id":"00000000000000000040", "comparator":"GreaterThanOrEqualTo", "worker_action":"PreviewHit", "qualification_values":[ "100" ], "caller_meets_requirement":null, "qualification_type":{ "qualification_type_id":"00000000000000000040", "name":"Total approved HITs", "visibility":true, "description":"This Qualification is generated automatically and reflects the number of HITs which you have submitted an answer that has been approved. Your score is a value greater than or equal to 0.", "has_test":false, "is_requestable":false, "keywords":"total,assignments,approved" }, "caller_qualification_value":{ "integer_value":null, "locale_value":{ "country":null, "subdivision":null } } }, { "qualification_type_id":"00000000000000000040", "comparator":"LessThanOrEqualTo", "worker_action":"PreviewHit", "qualification_values":[ "10000" ], "caller_meets_requirement":null, "qualification_type":{ "qualification_type_id":"00000000000000000040", "name":"Total approved HITs", "visibility":true, "description":"This Qualification is generated automatically and reflects the number of HITs which you have submitted an answer that has been approved. Your score is a value greater than or equal to 0.", "has_test":false, "is_requestable":false, "keywords":"total,assignments,approved" }, "caller_qualification_value":{ "integer_value":null, "locale_value":{ "country":null, "subdivision":null } } }, { "qualification_type_id":"38SUCLIH8F2EKN7F79243ZMC018DVQ", "comparator":"DoesNotExist", "worker_action":"PreviewHit", "qualification_values":[ ], "caller_meets_requirement":null, "qualification_type":{ "qualification_type_id":"38SUCLIH8F2EKN7F79243ZMC018DVQ", "name":"Exc: [1562964400-407052]", "visibility":true, "description":"Excluded from HIT 407052", "has_test":false, "is_requestable":true, "keywords":"" }, "caller_qualification_value":{ "integer_value":null, "locale_value":{ "country":null, "subdivision":null } } }, { "qualification_type_id":"3CE74LL4O7AZFGA0UGQGHW46O9VEKS", "comparator":"GreaterThanOrEqualTo", "worker_action":"ViewHitSet", "qualification_values":[ "100" ], "caller_meets_requirement":null, "qualification_type":{ "qualification_type_id":"3CE74LL4O7AZFGA0UGQGHW46O9VEKS", "name":"rhsnlk98", "visibility":true, "description":"rhsnlk98", "has_test":false, "is_requestable":true, "keywords":"" }, "caller_qualification_value":{ "integer_value":null, "locale_value":{ "country":null, "subdivision":null } } }, { "qualification_type_id":"000000000000000000L0", "comparator":"GreaterThanOrEqualTo", "worker_action":"PreviewHit", "qualification_values":[ "97" ], "caller_meets_requirement":null, "qualification_type":{ "qualification_type_id":"000000000000000000L0", "name":"HIT approval rate (%)", "visibility":true, "description":"This Qualification is generated automatically and reflects the percentage of HITs for which you have submitted an answer that has been approved divided by the total number of HITs that have been approved or rejected. Your score is a value between 0 and 100. A score of 100 indicates that every HIT you have submitted has been approved.", "has_test":false, "is_requestable":false, "keywords":"percent,assignments,approved" }, "caller_qualification_value":{ "integer_value":null, "locale_value":{ "country":null, "subdivision":null } } }, { "qualification_type_id":"00000000000000000071", "comparator":"In", "worker_action":"PreviewHit", "qualification_values":[ "US" ], "caller_meets_requirement":null, "qualification_type":{ "qualification_type_id":"00000000000000000071", "name":"Location", "visibility":true, "description":"The Location Qualification represents the location you specified with your mailing address. Some HITs may only be available to residents of particular countries, states, provinces or cities.", "has_test":false, "is_requestable":false, "keywords":"location" }, "caller_qualification_value":{ "integer_value":null, "locale_value":{ "country":null, "subdivision":null } } } ], "requester_url":"/requesters/A1165NJPZ7NRHY/projects.json?ref=w_pl_prvw" }, "expired_task_action_url":"/projects/3TO8OQV8SS7AASYDA776PS0ORD5LOY/tasks.json?ref=w_pl_prvw", "task_url":"/projects/3TO8OQV8SS7AASYDA776PS0ORD5LOY/tasks/371DNNCG44VU3DLRUTAR4FZSY848TH.json?assignment_id=37UEWGM5HU12YIM8HL1ID97WDOJ1RH&ref=w_pl_prvw" }, { "task_id":"3FHTJGYT9QJL8RPOD4J06TE6KBTGP7", "assignment_id":"3300DTYQT61BA9S6XPD3VEFWQLREQ0", "accepted_at":"2023-03-02T17:52:31.000Z", "deadline":"2023-03-02T18:52:31.000Z", "time_to_deadline_in_seconds":3566, "state":"Assigned", "question":{ "value":"https://www.mturkcontent.com/dynamic/hit?assignmentId=3300DTYQT61BA9S6XPD3VEFWQLREQ0&hitId=3FHTJGYT9QJL8RPOD4J06TE6KBTGP7&workerId=AN4TEA6EBEB2V&turkSubmitTo=https%3A%2F%2Fwww.mturk.com", "type":"InternalURL", "attributes":{ "FrameSourceAttribute":"https://www.mturkcontent.com/dynamic/hit?assignmentId=3300DTYQT61BA9S6XPD3VEFWQLREQ0&hitId=3FHTJGYT9QJL8RPOD4J06TE6KBTGP7&workerId=AN4TEA6EBEB2V&turkSubmitTo=https%3A%2F%2Fwww.mturk.com", "FrameHeight":"0" } }, "project":{ "hit_set_id":"3G2I6FODBFTUPDKWR5RHO3FIO036LC", "requester_id":"A1QLBEGFG76R2D", "requester_name":"Matt Frei (Verisk)", "title":"Edit PDF files", "description":"Make simple edits to provided PDF documents", "assignment_duration_in_seconds":3600, "creation_time":"2023-02-28T17:02:32.000Z", "assignable_hits_count":342, "latest_expiration_time":"2023-03-07T17:02:32.000Z", "caller_meets_requirements":false, "caller_meets_preview_requirements":false, "last_updated_time":"2023-02-28T17:02:32.000Z", "monetary_reward":{ "currency_code":"USD", "amount_in_dollars":1.0 }, "hit_requirements":[ { "qualification_type_id":"000000000000000000L0", "comparator":"GreaterThan", "worker_action":"PreviewHit", "qualification_values":[ "90" ], "caller_meets_requirement":null, "qualification_type":{ "qualification_type_id":"000000000000000000L0", "name":"HIT approval rate (%)", "visibility":true, "description":"This Qualification is generated automatically and reflects the percentage of HITs for which you have submitted an answer that has been approved divided by the total number of HITs that have been approved or rejected. Your score is a value between 0 and 100. A score of 100 indicates that every HIT you have submitted has been approved.", "has_test":false, "is_requestable":false, "keywords":"percent,assignments,approved" }, "caller_qualification_value":{ "integer_value":null, "locale_value":{ "country":null, "subdivision":null } } }, { "qualification_type_id":"00000000000000000040", "comparator":"GreaterThan", "worker_action":"PreviewHit", "qualification_values":[ "50" ], "caller_meets_requirement":null, "qualification_type":{ "qualification_type_id":"00000000000000000040", "name":"Total approved HITs", "visibility":true, "description":"This Qualification is generated automatically and reflects the number of HITs which you have submitted an answer that has been approved. Your score is a value greater than or equal to 0.", "has_test":false, "is_requestable":false, "keywords":"total,assignments,approved" }, "caller_qualification_value":{ "integer_value":null, "locale_value":{ "country":null, "subdivision":null } } } ], "requester_url":"/requesters/A1QLBEGFG76R2D/projects.json?ref=w_pl_prvw" }, "expired_task_action_url":"/projects/3G2I6FODBFTUPDKWR5RHO3FIO036LC/tasks.json?ref=w_pl_prvw", "task_url":"/projects/3G2I6FODBFTUPDKWR5RHO3FIO036LC/tasks/3FHTJGYT9QJL8RPOD4J06TE6KBTGP7.json?assignment_id=3300DTYQT61BA9S6XPD3VEFWQLREQ0&ref=w_pl_prvw" }, { "task_id":"3VIVIU06GWUDEU4UVT9AP4U1KS1MI0", "assignment_id":"3W92K5RLW7ZNFC1IS3W9CB4Z6355VH", "accepted_at":"2023-03-02T17:52:33.000Z", "deadline":"2023-03-02T18:52:33.000Z", "time_to_deadline_in_seconds":3568, "state":"Assigned", "question":{ "value":"https://proxy-dot-aquxr-endor.uc.r.appspot.com/studies/8cc1c1?assignmentId=3W92K5RLW7ZNFC1IS3W9CB4Z6355VH&hitId=3VIVIU06GWUDEU4UVT9AP4U1KS1MI0&workerId=AN4TEA6EBEB2V&turkSubmitTo=https%3A%2F%2Fwww.mturk.com", "type":"ExternalURL", "attributes":{ "FrameSourceAttribute":"https://proxy-dot-aquxr-endor.uc.r.appspot.com/studies/8cc1c1?assignmentId=3W92K5RLW7ZNFC1IS3W9CB4Z6355VH&hitId=3VIVIU06GWUDEU4UVT9AP4U1KS1MI0&workerId=AN4TEA6EBEB2V&turkSubmitTo=https%3A%2F%2Fwww.mturk.com", "FrameHeight":"0" } }, "project":{ "hit_set_id":"3DPZKFEUV4YYF3DZ7UJPETYJST34IL", "requester_id":"AFDMB61DD2BET", "requester_name":"Mturk Study", "title":"Feature Detection Task | 10-12 minutes | Earn $1.50", "description":"Detect features in an image (10-12 minutes)", "assignment_duration_in_seconds":3600, "creation_time":"2023-02-28T23:10:27.000Z", "assignable_hits_count":12, "latest_expiration_time":"2023-03-02T23:10:27.000Z", "caller_meets_requirements":false, "caller_meets_preview_requirements":false, "last_updated_time":"2023-02-28T23:10:27.000Z", "monetary_reward":{ "currency_code":"USD", "amount_in_dollars":1.0 }, "hit_requirements":[ { "qualification_type_id":"00000000000000000040", "comparator":"GreaterThanOrEqualTo", "worker_action":"AcceptHit", "qualification_values":[ "1" ], "caller_meets_requirement":null, "qualification_type":{ "qualification_type_id":"00000000000000000040", "name":"Total approved HITs", "visibility":true, "description":"This Qualification is generated automatically and reflects the number of HITs which you have submitted an answer that has been approved. Your score is a value greater than or equal to 0.", "has_test":false, "is_requestable":false, "keywords":"total,assignments,approved" }, "caller_qualification_value":{ "integer_value":null, "locale_value":{ "country":null, "subdivision":null } } }, { "qualification_type_id":"000000000000000000L0", "comparator":"GreaterThanOrEqualTo", "worker_action":"AcceptHit", "qualification_values":[ "90" ], "caller_meets_requirement":null, "qualification_type":{ "qualification_type_id":"000000000000000000L0", "name":"HIT approval rate (%)", "visibility":true, "description":"This Qualification is generated automatically and reflects the percentage of HITs for which you have submitted an answer that has been approved divided by the total number of HITs that have been approved or rejected. Your score is a value between 0 and 100. A score of 100 indicates that every HIT you have submitted has been approved.", "has_test":false, "is_requestable":false, "keywords":"percent,assignments,approved" }, "caller_qualification_value":{ "integer_value":null, "locale_value":{ "country":null, "subdivision":null } } }, { "qualification_type_id":"00000000000000000071", "comparator":"EqualTo", "worker_action":"AcceptHit", "qualification_values":[ "US" ], "caller_meets_requirement":null, "qualification_type":{ "qualification_type_id":"00000000000000000071", "name":"Location", "visibility":true, "description":"The Location Qualification represents the location you specified with your mailing address. Some HITs may only be available to residents of particular countries, states, provinces or cities.", "has_test":false, "is_requestable":false, "keywords":"location" }, "caller_qualification_value":{ "integer_value":null, "locale_value":{ "country":null, "subdivision":null } } } ], "requester_url":"/requesters/AFDMB61DD2BET/projects.json?ref=w_pl_prvw" }, "expired_task_action_url":"/projects/3DPZKFEUV4YYF3DZ7UJPETYJST34IL/tasks.json?ref=w_pl_prvw", "task_url":"/projects/3DPZKFEUV4YYF3DZ7UJPETYJST34IL/tasks/3VIVIU06GWUDEU4UVT9AP4U1KS1MI0.json?assignment_id=3W92K5RLW7ZNFC1IS3W9CB4Z6355VH&ref=w_pl_prvw" } ] } Â Quote Link to comment Share on other sites More sharing options...
kicken Posted March 2, 2023 Share Posted March 2, 2023 Your array A is still somewhat unclear. Is it like this? $arrayA = [ 'filters' => [ 'requester' => true ] , 'requesters' => [ 'GHS Research' ] ]; And you want to get a count of the values in $arrayA['requesters'] that do not exist in any of the $task['project']['requester_name'] values in array B? Quote Link to comment Share on other sites More sharing options...
gw1500se Posted March 2, 2023 Author Share Posted March 2, 2023 Exactly. Quote Link to comment Share on other sites More sharing options...
kicken Posted March 2, 2023 Share Posted March 2, 2023 Something like this then: $arrayA = [ 'filters' => [ 'requester' => true ] , 'requesters' => [ 'GHS Research', 'gw1500se', 'Kicken' ] ]; $arrayB = [ 'tasks' => [ ['project'=>['requester_name'=>'GHS Research']], ['project'=>['requester_name'=>'Example']], ['project'=>['requester_name'=>'gw1500se']] ] ]; $requesterList = array_column(array_column($arrayB['tasks'], 'project'), 'requester_name'); $count = count(array_diff($arrayA['requesters'], $requesterList)); var_dump($count); Â Quote Link to comment Share on other sites More sharing options...
kicken Posted March 3, 2023 Share Posted March 3, 2023 So, I just realized this was the JavaScript forum not the PHP forum. const arrayA = { 'filters': { 'requester': true } , 'requesters': [ 'GHS Research', 'gw1500se', 'Kicken' ] }; const arrayB = { 'tasks': [ {'project': {'requester_name': 'GHS Research'}}, {'project': {'requester_name': 'Example'}}, {'project': {'requester_name': 'gw1500se'}}, ] }; const requesterList = arrayB.tasks.map((i) => i.project.requester_name); const missing = arrayA.requesters.filter((i) => !requesterList.includes(i)); console.log(missing, missing.length); Â Quote Link to comment Share on other sites More sharing options...
gw1500se Posted March 3, 2023 Author Share Posted March 3, 2023 Thanks. I need to decipher that as some of those functions are new to me. Quote Link to comment Share on other sites More sharing options...
kicken Posted March 3, 2023 Share Posted March 3, 2023 12 hours ago, kicken said: const requesterList = arrayB.tasks.map((i) => i.project.requester_name); Array.map runs through the array passing each element to a callback function and returning a new array. The new array is composed of the value returned from that function. In the callback function here, i will be each task element. The callback returns the requester name of the task. The final a result is an array list of each requester name found in the tasks array. 12 hours ago, kicken said: const missing = arrayA.requesters.filter((i) => !requesterList.includes(i)); Array.filter also runs the every element of the array through a function and returns a new array. The callback is supposed to return true or false, and if it returns true, the original element is added to the new array. Any elements where the return value is false end up removed from the final array. The callback here takes an element from the arrayA.requsters list and checks if it exists in the requsterList build from the tasks. If it does, the function returns false and that item is stripped from the final array. End result is an array of requesters not found in the tasks.   Quote Link to comment Share on other sites More sharing options...
gw1500se Posted March 3, 2023 Author Share Posted March 3, 2023 Thanks. Quote Link to comment Share on other sites More sharing options...
gw1500se Posted March 7, 2023 Author Share Posted March 7, 2023 (edited) Getting this error: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'filter') Â Â Â at getCount (auto_select.js:62:38) Â Â Â at myExtension (auto_select.js:95:16) Â Â Â at async main (auto_select.js:148:7) on this line: const missing = arrayA.requesters.filter((i) => !requesterList.includes(i)); This is my function: function getCount(arrayA,arrayB) { const requesterList = arrayB.tasks.map((i) => i.project.requester_name); const missing = arrayA.requesters.filter((i) => !requesterList.includes(i)); return(missing); } Â Edited March 7, 2023 by gw1500se Quote Link to comment Share on other sites More sharing options...
kicken Posted March 7, 2023 Share Posted March 7, 2023 That's telling you that arrayA.requesters is undefined, not an array as expected. If it's possible for it to be undefined, add a check for that. If it should not ever be undefined, you need to figure out why it is.  Quote Link to comment Share on other sites More sharing options...
gw1500se Posted March 7, 2023 Author Share Posted March 7, 2023 I forgot about that, Thanks. Quote Link to comment Share on other sites More sharing options...
gw1500se Posted March 8, 2023 Author Share Posted March 8, 2023 I'm a bit confused by your code: const missing = arrayA.requesters.filter((i) => !requesterList.includes(i)); Missing contains the entries in arrayA.requesters rather than a list of those in requesterList. Quote Link to comment Share on other sites More sharing options...
kicken Posted March 8, 2023 Share Posted March 8, 2023 That's what you said you needed as far as I understood it. On 3/2/2023 at 3:04 PM, kicken said: values in $arrayA['requesters'] that do not exist in any of the $task['project']['requester_name'] values in array B If you want the other way, you could just reverse the array's. Quote Link to comment Share on other sites More sharing options...
gw1500se Posted March 8, 2023 Author Share Posted March 8, 2023 (edited) Thanks. I guess I do want it the other way around but I don't think it is that simple. The keys are diufferent. Edited March 8, 2023 by gw1500se Quote Link to comment Share on other sites More sharing options...
gw1500se Posted March 10, 2023 Author Share Posted March 10, 2023 (edited) So this is what I thought I should do: function getCount(arrayA,arrayB) { const requesterList = arrayB.tasks.map((i) => i.project.requester_name); // const missing = arrayA.requesters.filter((i) => !requesterList.includes(i)); const missing=requesterList.filter((i) => !arrayA.requesters.includes(i)); console.log(missing); return(missing.length); } Unfortunately I am not understanding the functions as this never returns anything (always 0). Edited March 10, 2023 by gw1500se Quote Link to comment Share on other sites More sharing options...
kicken Posted March 10, 2023 Share Posted March 10, 2023 It gives a result using the example data in my post above. Changing to const missing = requesterList.filter((i) => !arrayA.requesters.includes(i)); console.log(missing, missing.length); Gives the result [ 'Example' ] 1 Log your arrays and make sure they are what you think they are. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.