Home / Expert Answers / Computer Science / write-a-function-called-pluck-which-takes-an-array-of-objects-and-the-name-of-a-key-the-function-pa620

(Solved): Write a function called pluck, which takes an array of objects and the name of a key. The function ...




Write a function called pluck, which takes an array of objects and the name of a key. The function should return an array con
Write a function called pluck, which takes an array of objects and the name of a key. The function should return an array containing the value associated with that key for each object, or - 1 if that key is not present in the object.


We have an Answer from Expert

View Expert Answer

Expert Answer


#include #include #include #include using namespace std; vector pluck(vector> arr, string key) { vector result; for (auto i : arr) { if (i.find(key) != i.end()) {
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe