GithubHelp home page GithubHelp logo

js_functions's Introduction

#JavaScript Functions

Using the google shoping data from the previous exercise (also included in this repository) create some useful functions to answer the following questions.

Tip: for some of these you can re-use some of the code you created in the previous exercise.

##Examples

Below are some examples of some basic functions. This example is also included in the repository as examples.js so you can execute it.


//this function takes 2 numbers
//adds them together and returns the sum
var add = function(num1, num2){
	return num1 + num2;
};

//this function takes 2 numbers
//subtracts them and returns the difference
var subtract = function(num1,num2){
	return num1 - num2;
};

console.log(add(1,2));
//adds 1 and 2 and returns 3
// outputs: 3

console.log(subtract(3,1));
//subtracts 1 from 3
//outputs: 2

//calling functions in functions
console.log(subtract(add(1,2),1));
//outputs: 2

#Problems

##1.) getItems(array)

Create a function called getItems that simply returns the items array from the google product object.

##2.) getItemsByBrand(array, brand) Create a function called getItemsByBrand that takes an item array returns a new array of all items of a specified brand.

Test this function by searching for Sony, Cannon, Nikon and Panasonic.

##3.) getItemsByAuthor(array, author) Create a function called getItemsByAuthor that takes an item array and returns a new array of all items by a specified author.

Test this function by searching for Target, CDW, eBay

##4.) getAvailableProducts(array) Create function called getAvailableProducts that takes an item array and returns an array containing all of the available products (an available product is one with at least one availability of "inStock" in the inventories array)

##5.) Use your functions Use the functions you created in 1 - 5 to print find the following lists of items.

  • All items made by Nikon with the author eBay.
  • All items made by Sony.
  • All items made by Sony that are available.

BONUS: Create another search function and/or think of other interesting ways to combine the functions to preform useful searches.

js_functions's People

Contributors

itslenny avatar bridgpal avatar clairelyles avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.