Skip to content

Instantly share code, notes, and snippets.

@mmeigooni
Created May 17, 2017 04:45
Show Gist options
  • Save mmeigooni/6a06737da61fe97f82a477bdf59fe23b to your computer and use it in GitHub Desktop.
Save mmeigooni/6a06737da61fe97f82a477bdf59fe23b to your computer and use it in GitHub Desktop.

Set D

Prompt

//1. Write a function that takes in a number, and returns a string with that many number of stars ("*").

After prompt number 1, you are given this :

function assert(expectedBehavior, descriptionOfCorrectBehavior) {
  if (!expectedBehavior) {
    console.log(descriptionOfCorrectBehavior);
  } else {
    console.log('test passed');
  }
}

Study the function, and use it to test the function you just wrote for prompt number 1.

//2. Modify your previous function to return the given number of an input character. If the user does not input a character, return null.

Test your newly defined function.

//3. Study the format of the following data.

var allStars = [{
      name: "Dwyane Wade",
      pointsPerGame: 23.7,
      assistsPerGame: 5.8,
      reboundsPerGame: 4.8
    }, {
      name: "Kyle Lowry",
      pointsPerGame: 13.5,
      assistsPerGame: 5.7,
      reboundsPerGame: 4.0
    }, {
      name: "LeBron James",
      pointsPerGame: 27.2,
      assistsPerGame: 6.9,
      reboundsPerGame: 7.2
    }, {
      name: "Paul George",
      pointsPerGame: 16.9,
      assistsPerGame: 3.1,
      reboundsPerGame: 6.2
    }, {
      name: "Carmelo Anthony",
      pointsPerGame: 24.9,
      assistsPerGame: 3.2,
      reboundsPerGame: 6.6
    }, {
      name: "Stephen Curry",
      pointsPerGame: 22.4,
      assistsPerGame: 6.9,
      reboundsPerGame: 4.3
    }, {
      name: "Russell Westbrook",
      pointsPerGame: 21.5,
      assistsPerGame: 2.6,
      reboundsPerGame: 5.6
    }, {
      name: "Kobe Bryant",
      pointsPerGame: 25.0,
      assistsPerGame: 4.7,
      reboundsPerGame: 5.2
    }, {
      name: "Kevin Durant",
      pointsPerGame: 25.6,
      assistsPerGame: 2.9,
      reboundsPerGame: 5.6
    }, {
      name: "Kawhi Leonard",
      pointsPerGame: 14.3,
      assistsPerGame: 2.0,
      reboundsPerGame: 6.3
    }
]

//Your scouting manager only wants you to pay attention to players who get at least 6 rebounds per game. Create a function that returns an array of player names who fit this description.

var highReboundingPlayers = function(players){
    
}

//4. Right now your function looks for only players with 6 rebounds per game. Modify your function such that it takes in a target number and filters accordingly.

E.g.

highReboundingPlayers(allStars, 6); //returns a list of all-stars who get an average of at least 6 rebounds per game.

//5. Modify your function to take in a third argument that indicates which property you are interested in, and returns a filtered array based on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment