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
1.8 KiB
1.8 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 699c8e045ee7cb94ed2322d5 | Challenge 214: Domino Chain Validator | 28 | challenge-214 |
--description--
Given a 2D array representing a sequence of dominoes, determine whether it forms a valid chain.
- Each element in the array represents a domino and will be an array of two numbers from 1 to 6, (inclusive).
- For the chain to be valid, the second number of each domino must match the first number of the next domino.
- The first number of the first domino and the last number of the last domino don't need to match anything.
--hints--
isValidDominoChain([[1, 3], [3, 6], [6, 5]]) should return true.
assert.isTrue(isValidDominoChain([[1, 3], [3, 6], [6, 5]]));
isValidDominoChain([[6, 2], [3, 4], [4, 1]]) should return false.
assert.isFalse(isValidDominoChain([[6, 2], [3, 4], [4, 1]]));
isValidDominoChain([[2, 5], [5, 6], [5, 1]]) should return false.
assert.isFalse(isValidDominoChain([[2, 5], [5, 6], [5, 1]]));
isValidDominoChain([[4, 3], [3, 1], [1, 6], [6, 6], [6, 5], [5, 1], [1, 1], [1, 4], [4, 4], [4, 2]]) should return true.
assert.isTrue(isValidDominoChain([[4, 3], [3, 1], [1, 6], [6, 6], [6, 5], [5, 1], [1, 1], [1, 4], [4, 4], [4, 2]]));
isValidDominoChain([[2, 3], [3, 3], [3, 6], [6, 1], [1, 4], [3, 5], [5, 5], [5, 4], [4, 2], [2, 2]]) should return false.
assert.isFalse(isValidDominoChain([[2, 3], [3, 3], [3, 6], [6, 1], [1, 4], [3, 5], [5, 5], [5, 4], [4, 2], [2, 2]]));
--seed--
--seed-contents--
function isValidDominoChain(dominoes) {
return dominoes;
}
--solutions--
function isValidDominoChain(dominoes) {
for (let i = 0; i < dominoes.length - 1; i++) {
if (dominoes[i][1] !== dominoes[i+1][0]) return false
}
return true;
}