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

1.8 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
6a0dcc730cb92a616f86f0c0 Challenge 296: Schema Validator Part 2 28 challenge-296

--description--

Given an object (JavaScript) or dictionary (Python), determine if it matches the following schema:

{
  username: string,
  posts: number,
  verified: boolean
}
  • Extra keys are allowed

--hints--

isValidSchema({ username: "alice", posts: 10, verified: false }) should return true.

assert.isTrue(isValidSchema({ username: "alice", posts: 10, verified: false }));

isValidSchema({ username: "carol", posts: 15, verified: true, followers: 25 }) should return true.

assert.isTrue(isValidSchema({ username: "carol", posts: 15, verified: true, followers: 25 }));

isValidSchema({ username: "frank", posts: "21", verified: true }) should return false.

assert.isFalse(isValidSchema({ username: "frank", posts: "21", verified: true }));

isValidSchema({ username: "sam", posts: 17, verified: "false" }) should return false.

assert.isFalse(isValidSchema({ username: "sam", posts: 17, verified: "false" }));

isValidSchema({ username: "bill", verified: true }) should return false.

assert.isFalse(isValidSchema({ username: "bill", verified: true }));

isValidSchema({ username: "fred", verified: true }) should return false.

assert.isFalse(isValidSchema({ username: "fred", verified: true }));

isValidSchema({ username: 5, posts: 10, verified: true }) should return false.

assert.isFalse(isValidSchema({ username: 5, posts: 10, verified: true }));

--seed--

--seed-contents--

function isValidSchema(obj) {

  return obj;
}

--solutions--

function isValidSchema(obj) {
  return (
    typeof obj.username === 'string' &&
    typeof obj.posts === 'number' &&
    typeof obj.verified === 'boolean'
  );
}