• Tools: Node, Mocha, Chai


Write a mocha/chai test for a function called getLongestString that does the following:

Given an array of strings, it will return the string containing the most letters. If two strings are tied for the most, return the one which occurs first. If the array contains only one string, it should return it.

longestString(["abc", "abcd", "ab", "xyzz"]) //--> returns "abcd"


  • Parameters: An array containing strings.
  • Your test should use the following arrays as test cases
    • ["", "a", "bb", "cc", "dd", "ee"]
    • ["abc", "abcd", "ab", "xyzz"]
    • [""]


  • Write your test first
  • Run your tests before writing the function
  • Write your function
  • Pass all of the tests