PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/front/node_modules/bower/lib/node_modules/bower-config/node_modules/mout/doc/collection.md

https://gitlab.com/boxnia/NFU_MOVIL
Markdown | 233 lines | 144 code | 89 blank | 0 comment | 0 complexity | 886ee598decf2ec3e588c1e63ebd7b75 MD5 | raw file
  1. # collection #
  2. Methods for dealing with collections (Array or Objects).
  3. ## contains(list, value):Boolean
  4. Checks if collection contains value.
  5. ```js
  6. contains({a: 1, b: 2, c: 'bar'}, 2); // true
  7. contains([1, 2, 3], 'foo'); // false
  8. ```
  9. See: [array/contains](array.html#contains), [object/contains](object.html#contains)
  10. ## every(list, callback, [thisObj]):Boolean
  11. Tests whether all values in the collection pass the test implemented by the
  12. provided callback.
  13. ```js
  14. var obj = {
  15. a: 1,
  16. b: 2,
  17. c: 3,
  18. d: 'string'
  19. };
  20. every(obj, isNumber); // false
  21. ```
  22. See: [array/every](array.html#every), [object/every](object.html#every)
  23. ## filter(list, callback, [thisObj]):Array
  24. Filter collection properties.
  25. See: [array/filter](array.html#filter), [object/filter](object.html#filter)
  26. ## find(list, callback, [thisObj]):*
  27. Loops through all the values in the collection and returns the first one that
  28. passes a truth test (callback).
  29. **Important:** loop order over objects properties isn't guaranteed to be the
  30. same on all environments.
  31. ```js
  32. find({a: 'foo', b: 12}, isString); // 'foo'
  33. find(['foo', 12], isNumber); // 12
  34. ```
  35. See: [array/find](array.html#find), [object/find](object.html#find)
  36. ## forEach(list, callback, [thisObj])
  37. Loop through all values of the collection.
  38. See: [array/forEach](array.html#forEach), [object/forOwn](object.html#forOwn)
  39. ## map(list, callback, [thisObj]):Array
  40. Returns a new collection where the properties values are the result of calling
  41. the callback for each property in the original collection.
  42. See: [array/map](array.html#map), [object/map](object.html#map)
  43. ## max(list, [iterator]):*
  44. Returns maximum value inside collection or use a custom iterator to define how
  45. items should be compared.
  46. See: [`min()`](#min), [array/max](array.html#max), [object/max](object.html#max)
  47. ```js
  48. max({a: 100, b: 2, c: 1, d: 3, e: 200}); // 200
  49. max(['foo', 'lorem', 'amet'], function(val){
  50. return val.length;
  51. }); // 'lorem'
  52. ```
  53. ## min(list, [iterator]):*
  54. Returns minimum value inside collection or use a custom iterator to define how
  55. items should be compared.
  56. See: [`max()`](#max), [array/min](array.html#min), [object/min](object.html#min)
  57. ```js
  58. min([10, 2, 7]); // 2
  59. min({a: 'foo', b: 'lorem', c: 'amet'}, function(val){
  60. return val.length;
  61. }); // 'foo'
  62. ```
  63. ## pluck(list, propName):Array
  64. Extract a list of property values.
  65. ```js
  66. var users = [
  67. {
  68. name : 'John',
  69. age : 21
  70. },
  71. {
  72. name : 'Jane',
  73. age : 27
  74. }
  75. ];
  76. pluck(users, 'name'); // ["John", "Jane"]
  77. pluck(users, 'age'); // [21, 27]
  78. users = {
  79. first: {
  80. name : 'John',
  81. age : 21
  82. },
  83. second: {
  84. name : 'Mary',
  85. age : 25
  86. }
  87. };
  88. pluck(users, 'name'); // ['John', 'Mary']
  89. ```
  90. See: [array/pluck](array.html#pluck), [object/pluck](object.html#pluck)
  91. ## reduce(list, callback, initial, [thisObj]):*
  92. Apply a function against an accumulator and each value in the collection as to
  93. reduce it to a single value.
  94. ```js
  95. var obj = {a: 1, b: 2, c: 3, d: 4};
  96. function sum(prev, cur, key, list) {
  97. return prev + cur;
  98. }
  99. reduce(obj, sum); // 10
  100. ```
  101. See: [array/reduce](array.html#reduce), [object/reduce](object.html#reduce)
  102. ## reject(list, fn, [thisObj]):Array
  103. Creates a new array with all the elements that do **not** pass the truth test.
  104. Opposite of [`filter()`](#filter).
  105. ### Example
  106. ```js
  107. var numbers = [1, 2, 3, 4, 5];
  108. reject(numbers, function(x) { return (x % 2) !== 0; }); // [2, 4]
  109. var obj = {a: 1, b: 2, c: 3, d: 4, e: 5};
  110. reject(obj, function(x) { return (x % 2) !== 0; }); // [2, 4]
  111. ```
  112. See: [array/reject](array.html#reject), [object/reject](object.html#reject)
  113. ## size(list):Number
  114. Returns the number of values in the collection.
  115. ```js
  116. var obj = {
  117. foo : 1,
  118. bar : 2,
  119. lorem : 3
  120. };
  121. size(obj); // 3
  122. size([1,2,3]); // 3
  123. size(null); // 0
  124. ```
  125. See: [object/size](object.html#size)
  126. ## some(list, callback, [thisObj]):Boolean
  127. Tests whether any values in the collection pass the test implemented by the
  128. provided callback.
  129. ```js
  130. var obj = {
  131. a: 1,
  132. b: 2,
  133. c: 3,
  134. d: 'string'
  135. };
  136. some(obj, isNumber); // true
  137. some(obj, isString); // true
  138. some([1, 2, 3], isNumber) // true
  139. some([1, 2, 3], isString) // false
  140. ```
  141. See: [array/some](array.html#some), [object/some](object.html#some)
  142. -------------------------------------------------------------------------------
  143. For more usage examples check specs inside `/tests` folder. Unit tests are the
  144. best documentation you can get...