{"action":"created","issue":{"url":"https://api.github.com/repos/typicode/lowdb/issues/298","repository_url":"https://api.github.com/repos/typicode/lowdb","labels_url":"https://api.github.com/repos/typicode/lowdb/issues/298/labels{/name}","comments_url":"https://api.github.com/repos/typicode/lowdb/issues/298/comments","events_url":"https://api.github.com/repos/typicode/lowdb/issues/298/events","html_url":"https://github.com/typicode/lowdb/issues/298","id":350137693,"node_id":"MDU6SXNzdWUzNTAxMzc2OTM=","number":298,"title":"Filter unknown number of conditions","user":{"login":"ShlomoRosenheimer","id":5814588,"node_id":"MDQ6VXNlcjU4MTQ1ODg=","avatar_url":"https://avatars3.githubusercontent.com/u/5814588?v=4","gravatar_id":"","url":"https://api.github.com/users/ShlomoRosenheimer","html_url":"https://github.com/ShlomoRosenheimer","followers_url":"https://api.github.com/users/ShlomoRosenheimer/followers","following_url":"https://api.github.com/users/ShlomoRosenheimer/following{/other_user}","gists_url":"https://api.github.com/users/ShlomoRosenheimer/gists{/gist_id}","starred_url":"https://api.github.com/users/ShlomoRosenheimer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ShlomoRosenheimer/subscriptions","organizations_url":"https://api.github.com/users/ShlomoRosenheimer/orgs","repos_url":"https://api.github.com/users/ShlomoRosenheimer/repos","events_url":"https://api.github.com/users/ShlomoRosenheimer/events{/privacy}","received_events_url":"https://api.github.com/users/ShlomoRosenheimer/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-08-13T18:16:52Z","updated_at":"2018-08-13T19:14:50Z","closed_at":null,"author_association":"NONE","body":"I have something like this, with 2 filter conditions. How can I use filter() with an unknown number of conditions?\r\n\r\n```\r\nlet question = db.get('expressions')\r\n.filter({ active: isActive })\r\n.filter((v => min < v.count && v.count < max))\r\n        .orderBy(['asLastQuestionOn', 'count'], ['asc', 'asc'])\r\n        .take(1)\r\n        .value();\r\n```\r\n\r\nIs something like this possible?\r\n\r\n```\r\n// I can add new filters to the array \r\nlet f = [{ active: isActive }, (v => min < v.count && v.count < max)];\r\nlet question = db.get('expressions')\r\n.filter(f) \r\n        .orderBy(['asLastQuestionOn', 'count'], ['asc', 'asc'])\r\n        .take(1)\r\n        .value();\r\n```\r\n\r\nI failed to find a way to add multiple .filter() to my question. How can I stop the chain and continue?\r\n\r\nFails:\r\n```\r\nlet question = db.get('expressions')\r\n.filter({ active: isActive });\r\n\r\nquestion.filter((v => min < v.count && v.count < max))\r\n        .orderBy(['asLastQuestionOn', 'count'], ['asc', 'asc'])\r\n        .take(1)\r\n        .value();\r\n```"},"comment":{"url":"https://api.github.com/repos/typicode/lowdb/issues/comments/412631639","html_url":"https://github.com/typicode/lowdb/issues/298#issuecomment-412631639","issue_url":"https://api.github.com/repos/typicode/lowdb/issues/298","id":412631639,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMjYzMTYzOQ==","user":{"login":"ShlomoRosenheimer","id":5814588,"node_id":"MDQ6VXNlcjU4MTQ1ODg=","avatar_url":"https://avatars3.githubusercontent.com/u/5814588?v=4","gravatar_id":"","url":"https://api.github.com/users/ShlomoRosenheimer","html_url":"https://github.com/ShlomoRosenheimer","followers_url":"https://api.github.com/users/ShlomoRosenheimer/followers","following_url":"https://api.github.com/users/ShlomoRosenheimer/following{/other_user}","gists_url":"https://api.github.com/users/ShlomoRosenheimer/gists{/gist_id}","starred_url":"https://api.github.com/users/ShlomoRosenheimer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ShlomoRosenheimer/subscriptions","organizations_url":"https://api.github.com/users/ShlomoRosenheimer/orgs","repos_url":"https://api.github.com/users/ShlomoRosenheimer/repos","events_url":"https://api.github.com/users/ShlomoRosenheimer/events{/privacy}","received_events_url":"https://api.github.com/users/ShlomoRosenheimer/received_events","type":"User","site_admin":false},"created_at":"2018-08-13T19:14:50Z","updated_at":"2018-08-13T19:14:50Z","author_association":"NONE","body":"I managed to achieve conditional filtering like this. Feel free to show me how to do it better ;) as I would like to dynamically add filters..\r\n\r\n```\r\nlet question = db.get('expressions')\r\n        .filter((v => isFilterActive && v.active === requestData.filter.active))\r\n        .filter((v => isFilterType && v.type === requestData.filter.type))\r\n        .filter((v => isFilterLevel && v.level === requestData.filter.level))\r\n        .filter((v => isFilterCreatedOn && v.createdOn > filterCreatedOn))\r\n        .orderBy(['asLastQuestionOn', 'count'], ['asc', 'asc'])\r\n        .take(1)\r\n        .value();\r\n```"}}
{"actor":{"display_login":"ShlomoRosenheimer"}}