Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1.  
  2. var list = [
  3. {
  4. name: 'ivar',
  5. props: [
  6. {id: 1, value: 1},
  7. {id: 2, value: 5},
  8. {id: 3, value: 5},
  9. {id: 4, value: 10},
  10. {id: 5, value: 4},
  11. ]
  12. },
  13. {
  14. name: 'ivar2',
  15. props: [
  16. {id: 1, value: 11},
  17. {id: 2, value: 12},
  18. {id: 3, value: 7},
  19. {id: 4, value: 2},
  20. {id: 5, value: 3},
  21. ]
  22. },
  23. ];
  24.  
  25.  
  26. /*var newList = [];
  27. for(var object in list) {
  28. for(var index in list[object].props) {
  29. if(list[object].props[index].value > 10) {
  30. newList.push(list[object]);
  31. break;
  32. }
  33. }
  34. }
  35. list = newList;*/
  36.  
  37. /*var newList = [];
  38. list.forEach(function(object){
  39. object.props.some(function(index){
  40. if(index.value > 10) {
  41. newList.push(object);
  42. return true;
  43. }
  44. });
  45. });
  46. list = newList;*/
  47.  
  48. // param value by defaul 10;
  49. // param onlyBigItems by default 0 return object;
  50. // param onlyBigItems if = 1 return object with items that matched condition (> value);
  51. function filterList(onlyBigItems= 0, value = 10) {
  52. var newList = [];
  53. list.forEach(function(object){
  54. var obj = {};
  55. object.props.some(function(index){
  56. if(index.value > value) {
  57. if(onlyBigItems) {
  58. obj.name = object.name;
  59. obj.props = object.props.filter(function(item){
  60. return item.value > value;
  61. });
  62. newList.push(obj);
  63. } else {
  64. newList.push(object);
  65. }
  66. return true;
  67. }
  68. });
  69. });
  70. return newList;
  71. }
  72.  
  73. var list = filterList(null, 10);
  74. console.log(list);
  75.  
  76.  
  77.  
  78.  
  79. <?php
  80.  
  81. class User
  82. {
  83. private $_db;
  84. function __construct() {
  85. try {
  86.  
  87. $this->_db = DBHandler::instance(); // Singleton pattern if exists return else creat new connection
  88. } catch (PDOException $e) {
  89. echo '<p class="bg-danger">'.$e->getMessage().'</p>';;
  90. }
  91. }
  92.  
  93. public function authorize($login, $password) {
  94. $login = addslashes($login);
  95. $password = addslashes($password);
  96.  
  97. try {
  98. $stmt = $this->_db->prepare('SELECT * FROM users WHERE login = :login AND password = :password');
  99. $stmt->bindParam(':login', $login);
  100. $stmt->bindParam(':password', $password);
  101. $stmt->execute();
  102. $user = $stmt->fetch();
  103. } catch(PDOException $e) {
  104. echo '<p class="bg-danger">'.$e->getMessage().'</p>';
  105. }
  106. $this->authorized = !!$user;
  107. }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement