Advertisement
Guest User

Untitled

a guest
Mar 6th, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. Column IN ('a', 'b', 'c')
  2.  
  3. if (expression1 || expression2 || str === 'a' || str === 'b' || str === 'c') {
  4. // do something
  5. }
  6.  
  7. if (expression1 || expression2 || {a:1, b:1, c:1}[str]) {
  8. // do something
  9. }
  10.  
  11. var str = 'a',
  12. flag = false;
  13.  
  14. switch (str) {
  15. case 'a':
  16. case 'b':
  17. case 'c':
  18. flag = true;
  19. default:
  20. }
  21.  
  22. if (expression1 || expression2 || flag) {
  23. // do something
  24. }
  25.  
  26. if (!Array.prototype.indexOf) {
  27. Array.prototype.indexOf = function(item) {
  28. var i = this.length;
  29. while (i--) {
  30. if (this[i] === item) return i;
  31. }
  32. }
  33. return -1;
  34. }
  35.  
  36. if (['a', 'b', 'c'].indexOf(str) >= 0) {
  37. //do something
  38. }
  39.  
  40. if (/Foo|Bar|Baz/.test(str)) {
  41. // ...
  42. }
  43.  
  44.  
  45. if (str.match("Foo|Bar|Baz")) {
  46. // ...
  47. }
  48.  
  49. if (!Array.prototype.indexOf) {
  50. Array.prototype.indexOf = function(item) {
  51. var i = this.length;
  52. while (i--) {
  53. if (this[i] === item) return i;
  54. }
  55. return -1;
  56. }
  57. }
  58.  
  59. >>> ("something" in {"a string":"", "somthing":"", "another string":""})
  60. false
  61. >>> ("something" in {"a string":"", "something":"", "another string":""})
  62. true
  63.  
  64. >>> a = ["a string", "something", "another string"];
  65. >>> b = {};
  66. >>> for(var i=0; i<a.length;i++){b[a[i]]="";} /* Transform the array in a dict */
  67. >>> ("something" in b)
  68. true
  69.  
  70. js> a = ['foo', 'bar', 'baz']
  71. foo,bar,baz
  72. js> a.indexOf('bar')
  73. 1
  74. js> a.indexOf('quux')
  75. -1
  76.  
  77. function inList(psString, psList)
  78. {
  79. var laList = psList.split(',');
  80.  
  81. var i = laList.length;
  82. while (i--) {
  83. if (laList[i] === psString) return true;
  84. }
  85. return false;
  86. }
  87.  
  88. if (inList('Houston', 'LA,New York,Houston') {
  89. // THEN do something when your string is in the list
  90. }
  91.  
  92. String.prototype.inList=function(list){
  93. return ( Array.apply(null, arguments).indexOf(this.toString()) != -1)
  94. }
  95.  
  96. var x = 'abc';
  97. if (x.inList('aaa','bbb','abc') )
  98. console.log('yes');
  99. else
  100. console.log('no');
  101.  
  102. String.prototype.inList=function(list){
  103. return ( list.indexOf(this.toString()) != -1)
  104. }
  105.  
  106. var x = 'abc';
  107. if (x.inList(['aaa','bbb','abc']) )
  108. console.log('yes')
  109.  
  110. var list = ['a', 'b', 'c'];
  111. if (list.include(str)) {
  112. // do stuff
  113. }
  114.  
  115. function in_list(needle, hay)
  116. {
  117. var i, len;
  118.  
  119. for (i = 0, len = hay.length; i < len; i++)
  120. {
  121. if (hay[i] == needle) { return true; }
  122. }
  123.  
  124. return false;
  125. }
  126.  
  127. var alist = ["test"];
  128.  
  129. console.log(in_list("test", alist));
  130.  
  131. if ('abcdefghij'.indexOf(str) >= 0) {
  132. //do something
  133. }
  134.  
  135. // checking to see if var 'column' is in array ['a', 'b', 'c']
  136.  
  137. if (column.isAmong(['a', 'b', 'c']) {
  138. // do something
  139. }
  140.  
  141. Object.prototype.isAmong = function (MyArray){
  142. for (var a=0; a<MyArray.length; a++) {
  143. if (this === MyArray[a]) { return true;}
  144. }
  145. return false;
  146. }
  147.  
  148. var str = 'some string with a',
  149. list = ['a', 'b', 'c'],
  150. rx = new RegExp(list.join('|'));
  151.  
  152. rx.test(str);
  153.  
  154. new RegExp(list.join('|')).text(str);
  155.  
  156. var rx = new RegExp(list.join('|').concat('/i'));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement