Git Product home page Git Product logo

f5's Introduction

Iterator

Function: iterator([arg1[, arg2[, ...]]]) Arguments: arg1, arg2, ... Each argument can be either an array or another iterator.

This function returns an iterator object which provides two methods: next() and hasNext(). Each successive call to the iterator's next() method should return the next element in an iteration of the logical list of elements which would be the result of concatenating each element of the collections passed as arguments to the constructor of this iterator. Note that this list is never actually generated by the underlying implementation. As its name implies, the hasNext() method should return true whenever a successive call to the next() would return a value which is not undefined.

Example: The following should produce the output "123456789ABCDEF".

  var iter1 = iterator(["4", "5", "6"]);
  var iter2 = iterator(["A", "B", "C"]);
  var iter3 = iterator(iter2, ["D", "E", "F"]);
  var iter4 = iterator(["1", "2", "3"], iter1, ["7", "8", "9"], iter3);

  var output = "";
  while (iter4.hasNext()) {
      output += iter4.next();
  }
  console.log(output);

BNB

Consider the following problem:
    There are m distinct buckets and n identical balls and each bucket can contain 0 or more balls.
    All balls are arranged into the buckets, and there several combinations to arrange them.
    For example, if there are 2 buckets and 3 balls, we can have the following arrangement:
    
           bucket 1  |  bucket 2 
           ---------------------
               3     |     0
               2     |     1
               1     |     2
               0     |     3

    Another example, where m=3 and n=3:
   
           bucket 1  |  bucket 2  |  bucket 3
           ----------------------------------
               3     |     0      |     0
               2     |     1      |     0
               2     |     0      |     1
               1     |     2      |     0
               1     |     1      |     1
               1     |     0      |     2
               0     |     3      |     0
               0     |     2      |     1
               0     |     1      |     2
               0     |     0      |     3

Write a function that receives m (number of buckets) and n (number of balls) as arguments and prints out 
all of the possible balls-in-buckets permutations. Please note that each permutation must be printed 
out once. 

** Helper function/s are allowed and are encouraged.

f5's People

Contributors

erana111 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.