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

2.0 KiB
Raw Permalink Blame History

id, title, challengeType, dashedName
id title challengeType dashedName
68af0687ef34c76c28ffa54d Challenge 33: Screen Time 28 challenge-33

--description--

Given an input array of seven integers, representing a week's time, where each integer is the amount of hours spent on your phone that day, determine if it is too much screen time based on these constraints:

  • If any single day has 10 hours or more, it's too much.
  • If the average of any three days in a row is greater than or equal to 8 hours, its too much.
  • If the average of the seven days is greater than or equal to 6 hours, it's too much.

--hints--

tooMuchScreenTime([1, 2, 3, 4, 5, 6, 7]) should return false.

assert.isFalse(tooMuchScreenTime([1, 2, 3, 4, 5, 6, 7]));

tooMuchScreenTime([7, 8, 8, 4, 2, 2, 3]) should return false.

assert.isFalse(tooMuchScreenTime([7, 8, 8, 4, 2, 2, 3]));

tooMuchScreenTime([5, 6, 6, 6, 6, 6, 6]) should return false.

assert.isFalse(tooMuchScreenTime([5, 6, 6, 6, 6, 6, 6]));

tooMuchScreenTime([1, 2, 3, 11, 1, 3, 4]) should return true.

assert.isTrue(tooMuchScreenTime([1, 2, 3, 11, 1, 3, 4]));

tooMuchScreenTime([1, 2, 3, 10, 2, 1, 0]) should return true.

assert.isTrue(tooMuchScreenTime([1, 2, 3, 10, 2, 1, 0]));

tooMuchScreenTime([3, 3, 5, 8, 8, 9, 4]) should return true.

assert.isTrue(tooMuchScreenTime([3, 3, 5, 8, 8, 9, 4]));

tooMuchScreenTime([3, 9, 4, 8, 5, 7, 6]) should return true.

assert.isTrue(tooMuchScreenTime([3, 9, 4, 8, 5, 7, 6]));

--seed--

--seed-contents--

function tooMuchScreenTime(hours) {

  return hours;
}

--solutions--

function tooMuchScreenTime(hours) {
  for (let h of hours) {
    if (h >= 10) return true;
  }

  for (let i = 0; i <= 4; i++) {
    const avg3 = (hours[i] + hours[i+1] + hours[i+2]) / 3;
    if (avg3 >= 8) return true;
  }

  const weeklyAvg = hours.reduce((sum, h) => sum + h, 0) / 7;
  if (weeklyAvg >= 6) return true;

  return false;
}