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

id, title, challengeType, dashedName
id title challengeType dashedName
68b7cadffed0e75a517da66f Challenge 50: Longest Word 28 challenge-50

--description--

Given a sentence, return the longest word in the sentence.

  • Ignore periods (.) when determining word length.
  • If multiple words are ties for the longest, return the first one that occurs.

--hints--

getLongestWord("coding is fun") should return "coding".

assert.equal(getLongestWord("coding is fun"), "coding");

getLongestWord("Coding challenges are fun and educational.") should return "educational".

assert.equal(getLongestWord("Coding challenges are fun and educational."), "educational");

getLongestWord("This sentence has multiple long words.") should return "sentence".

assert.equal(getLongestWord("This sentence has multiple long words."), "sentence");

--seed--

--seed-contents--

function getLongestWord(sentence) {

  return sentence;
}

--solutions--

function getLongestWord(sentence) {
  const words = sentence.split(' ');

  let longest = '';
  for (let word of words) {
    const cleanWord = word.replace(/\./g, '');
    if (cleanWord.length > longest.length) {
      longest = cleanWord;
    }
  }

  return longest;
}