Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var list = [
- {
- name: 'ivar',
- props: [
- {id: 1, value: 1},
- {id: 2, value: 5},
- {id: 3, value: 5},
- {id: 4, value: 10},
- {id: 5, value: 4},
- ]
- },
- {
- name: 'ivar2',
- props: [
- {id: 1, value: 11},
- {id: 2, value: 12},
- {id: 3, value: 7},
- {id: 4, value: 2},
- {id: 5, value: 3},
- ]
- },
- ];
- /*var newList = [];
- for(var object in list) {
- for(var index in list[object].props) {
- if(list[object].props[index].value > 10) {
- newList.push(list[object]);
- break;
- }
- }
- }
- list = newList;*/
- /*var newList = [];
- list.forEach(function(object){
- object.props.some(function(index){
- if(index.value > 10) {
- newList.push(object);
- return true;
- }
- });
- });
- list = newList;*/
- // param value by defaul 10;
- // param onlyBigItems by default 0 return object;
- // param onlyBigItems if = 1 return object with items that matched condition (> value);
- function filterList(onlyBigItems= 0, value = 10) {
- var newList = [];
- list.forEach(function(object){
- var obj = {};
- object.props.some(function(index){
- if(index.value > value) {
- if(onlyBigItems) {
- obj.name = object.name;
- obj.props = object.props.filter(function(item){
- return item.value > value;
- });
- newList.push(obj);
- } else {
- newList.push(object);
- }
- return true;
- }
- });
- });
- return newList;
- }
- var list = filterList(null, 10);
- console.log(list);
- <?php
- class User
- {
- private $_db;
- function __construct() {
- try {
- $this->_db = DBHandler::instance(); // Singleton pattern if exists return else creat new connection
- } catch (PDOException $e) {
- echo '<p class="bg-danger">'.$e->getMessage().'</p>';;
- }
- }
- public function authorize($login, $password) {
- $login = addslashes($login);
- $password = addslashes($password);
- try {
- $stmt = $this->_db->prepare('SELECT * FROM users WHERE login = :login AND password = :password');
- $stmt->bindParam(':login', $login);
- $stmt->bindParam(':password', $password);
- $stmt->execute();
- $user = $stmt->fetch();
- } catch(PDOException $e) {
- echo '<p class="bg-danger">'.$e->getMessage().'</p>';
- }
- $this->authorized = !!$user;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement