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

70 lines
1.1 KiB
Markdown

---
id: 6a0dcc730cb92a616f86f0bf
title: "Challenge 295: Schema Validator Part 1"
challengeType: 28
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--
`isValidSchema({ username: "bob" })` should return `true`.
```js
assert.isTrue(isValidSchema({ username: "bob" }));
```
`isValidSchema({ username: "jen", posts: 30 })` should return `true`.
```js
assert.isTrue(isValidSchema({ username: "jen", posts: 30 }));
```
`isValidSchema({ username: "" })` should return `true`.
```js
assert.isTrue(isValidSchema({ username: "" }));
```
`isValidSchema({ username: 7 })` should return `false`.
```js
assert.isFalse(isValidSchema({ username: 7 }));
```
`isValidSchema({ posts: 25 })` should return `false`.
```js
assert.isFalse(isValidSchema({ posts: 25 }));
```
# --seed--
## --seed-contents--
```js
function isValidSchema(obj) {
return obj;
}
```
# --solutions--
```js
function isValidSchema(obj) {
return typeof obj.username === 'string';
}
```