Module ObjectRange
ObjectRange <ul><li>Ranges  represent an interval of values. The value type just needs to be “compatible,”  </li></ul><ul>...
ObjectRange <ul><li>Examples; </li></ul><ul><li>1)$A($R( 1 ,  5 )).join( ', ' ) </li></ul><ul><li>   // -> '1, 2, 3, 4, 5'...
ObjectRange <ul><li>Examples; </li></ul><ul><li>1)$R( 1 ,  10 ).include( 5 ) </li></ul><ul><li>// -> true </li></ul><ul><l...
Upcoming SlideShare
Loading in …5
×

Object Range

489 views

Published on

Introduction to javascript

  • Be the first to comment

  • Be the first to like this

Object Range

  1. 1. Module ObjectRange
  2. 2. ObjectRange <ul><li>Ranges represent an interval of values. The value type just needs to be “compatible,” </li></ul><ul><li>include(value) -> Boolean </li></ul><ul><li>Determines whether the value is included in the range </li></ul><ul><li>This assumes the values in the range have a valid strict weak ordering (have valid semantics for the < operator). </li></ul><ul><li>ObjectRange mixes in Enumerable, which makes ranges very versatile. </li></ul><ul><li>ObjectRange does provide a constructor, the preferred way to obtain a range is to use the $R utility function, </li></ul><ul><li>This method overrides the default version of include, and is way more efficient </li></ul><ul><li>it uses a maximum of two comparisons </li></ul>
  3. 3. ObjectRange <ul><li>Examples; </li></ul><ul><li>1)$A($R( 1 ,  5 )).join( ', ' ) </li></ul><ul><li>   // -> '1, 2, 3, 4, 5' 2) </li></ul><ul><li>2) $R( 1 ,  5 ).zip([ 'one' ,  'two' ,  'three' ,  'four' ,  'five' ],  function (tuple) {  return  tuple.join( ' = ' ); }) </li></ul><ul><li>  // > ['1 = one', '2 = two', '3 = three', '4 = four',  '5 = five'] </li></ul><ul><li>3)$A($R( 'a' ,  'e' )) </li></ul><ul><li>   // -> ['a', 'b', 'c', 'd', 'e'], no surprise there </li></ul><ul><li>  </li></ul><ul><li>  </li></ul>
  4. 4. ObjectRange <ul><li>Examples; </li></ul><ul><li>1)$R( 1 ,  10 ).include( 5 ) </li></ul><ul><li>// -> true </li></ul><ul><li>2)$R( 'a' ,  'h' ).include( 'x' ) </li></ul><ul><li>// -> false </li></ul><ul><li>3)$R( 1 ,  10 ).include( 10 ) </li></ul><ul><li>// -> true </li></ul><ul><li>4)$R( 1 ,  10 ,  true ).include( 10 ) </li></ul><ul><li>// -> false </li></ul>

×