TEST1

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
With regex
function useSearchValue(initialState) {
  const [searchValue, setSearchValue] = useState(initialState)

  function setFormattedSearchValue(currentSearchValue) {
    const lastChar = currentSearchValue[currentSearchValue.length - 1]
    const whiteSpace = ' '
    const capitalLetterRegex = new RegExp(/[A-Z]/)
    if (lastChar && lastChar === whiteSpace) {
      return
    }
    if (lastChar && capitalLetterRegex.test(lastChar)) {
      setSearchValue(currentSearchValue.toLowerCase())
      return
    }
    setSearchValue(currentSearchValue)
  }
  return [searchValue, setFormattedSearchValue]
}
ready
Without regex
function useSearchValue(initialState) {
  const [searchValue, setSearchValue] = useState(initialState)

  function setFormattedSearchValue(currentSearchValue) {
    const lastChar = currentSearchValue[currentSearchValue.length - 1]
    const whiteSpace = ' '
    if (lastChar && lastChar === whiteSpace) {
      return
    }
    setSearchValue(currentSearchValue.toLowerCase())
  }
  return [searchValue, setFormattedSearchValue]
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.