Which required fields are missing
A form submission arrives as a bag of strings and the server checks it before touching the database.
- A field is missing when its key is absent, or its value is empty or only whitespace.
- Report them in the order the requirements were given, not the order the payload happens to be in.
- Nothing required means nothing missing.
missingFields(payload: map<string, string>, required: list<string>) → list<string>
Go needs a compiler and Drill does not host one yet, so this page is the reference rather than an exercise: the problem, worked examples, and the solution in full. To type it out, the same problem runs in Python.
Where you start
func missingFields(payload map[string]string, required []string) []string {
}
Worked examples
| Call | Result |
|---|---|
missingFields(map[string]string{"name": "Ada", "email": ""}, []string{"name", "email", "phone"}) | []string{"email", "phone"} |
missingFields(map[string]string{"name": " "}, []string{"name"}) | []string{"name"} |
missingFields(map[string]string{"name": "Ada"}, []string{"name"}) | []string{} |
missingFields(map[string]string{}, []string{}) | []string{} |
Hint
Walk the requirements, not the payload — that is what fixes the output order.
Reference solution in Go
func missingFields(payload map[string]string, required []string) []string {
result := []string{}
for _, key := range required {
if strings.TrimSpace(payload[key]) == "" {
result = append(result, key)
}
}
return result
}