Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

83 lines
1.5 KiB
Markdown

---
id: 6a0dcc730cb92a616f86f0bf
title: "Challenge 295: Schema Validator Part 1"
challengeType: 29
dashedName: challenge-295
---
# --description--
Given an object (JavaScript) or dictionary (Python), determine if it matches the following schema:
```json
{
username: string
}
```
- Extra keys are allowed
# --hints--
`is_valid_schema({"username": "bob"})` should return `True`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_valid_schema({"username": "bob"}), True)`)
}})
```
`is_valid_schema({"username": "jen", "posts": 30})` should return `True`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_valid_schema({"username": "jen", "posts": 30}), True)`)
}})
```
`is_valid_schema({"username": ""})` should return `True`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_valid_schema({"username": ""}), True)`)
}})
```
`is_valid_schema({"username": 7})` should return `False`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_valid_schema({"username": 7}), False)`)
}})
```
`is_valid_schema({"posts": 25})` should return `False`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_valid_schema({"posts": 25}), False)`)
}})
```
# --seed--
## --seed-contents--
```py
def is_valid_schema(obj):
return obj
```
# --solutions--
```py
def is_valid_schema(obj):
return isinstance(obj.get("username"), str)
```