From 371f0c08f3d34269e0f33cb806e9f0df021a5f60 Mon Sep 17 00:00:00 2001 From: ricenzca Date: Thu, 14 Mar 2019 18:25:27 +0800 Subject: [PATCH 1/2] add new index.html and scrit.js and js/google_shopping_function.js --- index.html | 11 ++++ js/google_shopping_functions.js | 90 ++++++++++++++++++++++++++++++++- script.js | 6 +++ 3 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 index.html create mode 100644 script.js diff --git a/index.html b/index.html new file mode 100644 index 0000000..390e834 --- /dev/null +++ b/index.html @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/js/google_shopping_functions.js b/js/google_shopping_functions.js index bfbfdcf..27aea62 100755 --- a/js/google_shopping_functions.js +++ b/js/google_shopping_functions.js @@ -11,7 +11,95 @@ function getItemsCount(itemData) { /* * Define and use your functions here */ +//1.) getItems(objectData) +//Create a function called getItems that simply returns the items array from the google product object. +function getItems(objectData) { + return objectData.items; +} + +//2.) getItemsByBrand(items, brand) +//Create a function called getItemsByBrand that takes an item array returns a new array of all items of a specified brand. +function getItemsByBrand(items, brand) { + var arrayBrand = []; + for (i=0; i Date: Thu, 14 Mar 2019 22:57:04 +0800 Subject: [PATCH 2/2] updated js/google_shopping_function.js --- js/google_shopping_functions.js | 167 +++++++++++++++++++++++++------- 1 file changed, 133 insertions(+), 34 deletions(-) diff --git a/js/google_shopping_functions.js b/js/google_shopping_functions.js index 27aea62..9e25dec 100755 --- a/js/google_shopping_functions.js +++ b/js/google_shopping_functions.js @@ -4,8 +4,8 @@ * input: accepts full item data * output: returns the length of the items array */ -function getItemsCount(itemData) { - return itemData.items.length; +function getItemsCount(products) { + return products.items.length; } /* @@ -55,51 +55,150 @@ function getAvailableProducts(items) { return arrayAvail; } +//Search by max price +function searchByMaxP (items, price) { + var arrayMaxP = []; + for (i=0; i price) { + arrayMinP.push(items[i]); + } + } + return arrayMinP; +} +//Search by country +function getItemsByCountry(items, country) { + var arrayCtry = []; + for (i=0; i