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.1 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
6a2037a68a0bc2aef0006006 Challenge 344: Golden Ratio 28 challenge-344

--description--

Given two numbers, determine if their ratio approximates the golden ratio.

  • Use a golden ratio of 1.618
  • Allow a tolerance of 0.01

--hints--

isGoldenRatio(21, 34) should return true.

assert.isTrue(isGoldenRatio(21, 34));

isGoldenRatio(15, 20) should return false.

assert.isFalse(isGoldenRatio(15, 20));

isGoldenRatio(8, 13) should return true.

assert.isTrue(isGoldenRatio(8, 13));

isGoldenRatio(10, 16) should return false.

assert.isFalse(isGoldenRatio(10, 16));

isGoldenRatio(1618, 1000) should return true.

assert.isTrue(isGoldenRatio(1618, 1000));

isGoldenRatio(88, 55) should return false.

assert.isFalse(isGoldenRatio(88, 55));

--seed--

--seed-contents--

function isGoldenRatio(a, b) {

  return a;
}

--solutions--

function isGoldenRatio(a, b) {
  const goldenRatio = 1.618;
  const ratio = Math.max(a, b) / Math.min(a, b);
  return Math.abs(ratio - goldenRatio) <= 0.01;
}