Giter Site home page Giter Site logo

choose-random's Introduction

ChooseRandom Assignment

Students are to implement the chooseRandom function from the skeleton provided in lib.js. This function takes an array and the number of random items to choose from the array (numItems). It should return a new array containing the correct number of randomly selected, unique items from the original array. Students must export their createRandom function from the lib.js file in order to run the included test cases.

Goal


Have students practice a more complex problem in JavaScript which will allow them to explore more features of the language than some of the fundamental code wars problems offer.

Tasks

  • Implement chooseRandom function
  • Should take 2 parameters, array and number
  • array should default to an empty array
  • If array has length 0 or 1, then simply return it
  • numItems must be checked to ensure it is a in the range 1 to array.length (inclusive)
  • If numItems is outside of the correct range, then it should be set to a random number within the correct range
  • complete the skeleton for the randomIndices array
  • randomIndices should be an array of length numItems and contain unique numbers between 0 and array.length-1 which represent the indices of array
  • Filter array returning a new array containing only values which correlate to the indices included in randomIndices
  • Should always return an array
  • Should not mutate the array passed in
  • Should return a random array if possible (size > 1)
  • Should return an array of the passed in length
  • Run command npm run test and ensure all tests pass successfully

choose-random's People

Contributors

anubhawm avatar wmarttala 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.