Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Obj.js 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // Generated by LiveScript 1.4.0
  2. var values, keys, pairsToObj, objToPairs, listsToObj, objToLists, empty, each, map, compact, filter, reject, partition, find;
  3. values = function(object){
  4. var i$, x, results$ = [];
  5. for (i$ in object) {
  6. x = object[i$];
  7. results$.push(x);
  8. }
  9. return results$;
  10. };
  11. keys = function(object){
  12. var x, results$ = [];
  13. for (x in object) {
  14. results$.push(x);
  15. }
  16. return results$;
  17. };
  18. pairsToObj = function(object){
  19. var i$, len$, x, resultObj$ = {};
  20. for (i$ = 0, len$ = object.length; i$ < len$; ++i$) {
  21. x = object[i$];
  22. resultObj$[x[0]] = x[1];
  23. }
  24. return resultObj$;
  25. };
  26. objToPairs = function(object){
  27. var key, value, results$ = [];
  28. for (key in object) {
  29. value = object[key];
  30. results$.push([key, value]);
  31. }
  32. return results$;
  33. };
  34. listsToObj = curry$(function(keys, values){
  35. var i$, len$, i, key, resultObj$ = {};
  36. for (i$ = 0, len$ = keys.length; i$ < len$; ++i$) {
  37. i = i$;
  38. key = keys[i$];
  39. resultObj$[key] = values[i];
  40. }
  41. return resultObj$;
  42. });
  43. objToLists = function(object){
  44. var keys, values, key, value;
  45. keys = [];
  46. values = [];
  47. for (key in object) {
  48. value = object[key];
  49. keys.push(key);
  50. values.push(value);
  51. }
  52. return [keys, values];
  53. };
  54. empty = function(object){
  55. var x;
  56. for (x in object) {
  57. return false;
  58. }
  59. return true;
  60. };
  61. each = curry$(function(f, object){
  62. var i$, x;
  63. for (i$ in object) {
  64. x = object[i$];
  65. f(x);
  66. }
  67. return object;
  68. });
  69. map = curry$(function(f, object){
  70. var k, x, resultObj$ = {};
  71. for (k in object) {
  72. x = object[k];
  73. resultObj$[k] = f(x);
  74. }
  75. return resultObj$;
  76. });
  77. compact = function(object){
  78. var k, x, resultObj$ = {};
  79. for (k in object) {
  80. x = object[k];
  81. if (x) {
  82. resultObj$[k] = x;
  83. }
  84. }
  85. return resultObj$;
  86. };
  87. filter = curry$(function(f, object){
  88. var k, x, resultObj$ = {};
  89. for (k in object) {
  90. x = object[k];
  91. if (f(x)) {
  92. resultObj$[k] = x;
  93. }
  94. }
  95. return resultObj$;
  96. });
  97. reject = curry$(function(f, object){
  98. var k, x, resultObj$ = {};
  99. for (k in object) {
  100. x = object[k];
  101. if (!f(x)) {
  102. resultObj$[k] = x;
  103. }
  104. }
  105. return resultObj$;
  106. });
  107. partition = curry$(function(f, object){
  108. var passed, failed, k, x;
  109. passed = {};
  110. failed = {};
  111. for (k in object) {
  112. x = object[k];
  113. (f(x) ? passed : failed)[k] = x;
  114. }
  115. return [passed, failed];
  116. });
  117. find = curry$(function(f, object){
  118. var i$, x;
  119. for (i$ in object) {
  120. x = object[i$];
  121. if (f(x)) {
  122. return x;
  123. }
  124. }
  125. });
  126. module.exports = {
  127. values: values,
  128. keys: keys,
  129. pairsToObj: pairsToObj,
  130. objToPairs: objToPairs,
  131. listsToObj: listsToObj,
  132. objToLists: objToLists,
  133. empty: empty,
  134. each: each,
  135. map: map,
  136. filter: filter,
  137. compact: compact,
  138. reject: reject,
  139. partition: partition,
  140. find: find
  141. };
  142. function curry$(f, bound){
  143. var context,
  144. _curry = function(args) {
  145. return f.length > 1 ? function(){
  146. var params = args ? args.concat() : [];
  147. context = bound ? context || this : this;
  148. return params.push.apply(params, arguments) <
  149. f.length && arguments.length ?
  150. _curry.call(context, params) : f.apply(context, params);
  151. } : f;
  152. };
  153. return _curry();
  154. }