Created
November 22, 2022 04:58
-
-
Save kaniket7209/8045cf8e1d8d55cbbad08d64ff66a64f to your computer and use it in GitHub Desktop.
JAVASCRIPT TEST
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// You have been given a sample data and the list of selected values. Your task will be to make the query for mongo collection. | |
// this is the sample value | |
let unique_fields = [ | |
{"key":"priority","operator":["==","!="],"type":"str","value":["normal","high","low","urgent"]}, | |
{"key":"status","operator":["==","!="],"type":"str","value":["open","pending"]}, | |
{"key":"account_domain","operator":["==","!="],"type":"str","value":["renault.co.in","rivian.com","lucidmotors.com", | |
"mercedes-benz.com","zoox.com","tata.com","bmw.com","kia.com","tesla.com","honda.com","toyota.com"]} | |
] | |
// this is the selected values, which can vary as per users choice . So handle the test cases correctly. | |
selected_values = ['normal','pending','high','rivian.com'] | |
// this function should return the output as shown below: | |
function makeQuery(unique_fields,selected_values){ | |
//write code here | |
} | |
let res = makeQuery(unique_fields,selected_values) | |
console.log(res) | |
----------------------------------------------------- | |
Sample Test Cases: | |
1. | |
Payload = ["urgent", "pending", "open","normal","rivian.com"] | |
Output = {"$and":[{"$or":[{"priority":"urgent"},{"priority":"normal"}]},{"$or":[{"status":"pending"},{"status":"open"}]},{"$or":[{"account_domain":"rivian.com"}]}]} | |
2. | |
Payload = ["kia.com", "normal", "high","pending","urgent"] | |
Output = {"$and":[{"$or":[{"account_domain":"kia.com"}]},{"$or":[{"priority":"normal"},{"priority":"high"},{"priority":"urgent"}]},{"$or":[{"status":"pending"}]}]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment