Find the Longest Word in a String

Return the length of the longest word in the provided sentence. Your response should be a number.

Using reduce

function findLongestWordLength(str) {
  if (str.length === 0) {
    return 0;
  }

  return str.split(' ').reduce((longest, curr) => {
    if (curr.length > longest) {
      longest = curr.length;
    } 
    return longest;
  }, 0);
}

Using ternary operator

function findLongestWordLength(str) {
  if (str.length === 0) {
    return 0;
  }
  return str.split(' ').reduce((longest, curr) => {
    return (curr.length > longest) ? curr.length : longest;
  }, 0);
}