Friday, March 24, 2023

ChatGPT Did Some Of My Job

Today is the day that ChatGPT did my job more effectively than I could.

It's the first time this has happened.

My task was to remove all Lodash references in this piece of code.

export function useFilteredMenuSections(
  menuCategory: MenuQuery['guestMenuCategory'] | undefined,
): MenuSectionFragment[] {
  const { searchQuery, dietaryPrefs } = useContext(MenuStoreContext)
  const selectedDietaryPrefs = values(dietaryPrefs)
  const sections = get('menuSections')(menuCategory)

  const menuItems = useMemo(
    () => flow(map('menuItems'), flatten)(sections),
    [sections],
  )

  const byDietaryPreferences = useCallback(
    ({ filterTags }) =>
      flow(
        intersection(selectedDietaryPrefs),
        isEqual(selectedDietaryPrefs),
      )(filterTags),
    [selectedDietaryPrefs],
  )

  // heaps more Lodash below here
}

The ChatGPT query was

Remove Lodash code references in the following code

and I pasted in the code above.

It spat out perfect Lodash removed code.

export const filteredMenuSections = (
  menuCategory: MenuCategory,
  dietaryPreferences: string[],
  searchQuery: string,
) => {
  const sections = menuCategory?.menuSections || []

  const menuItems = sections.flatMap((section) => section.menuItems)

  const byDietaryPreferences = (menuItem: MenuItem) => {
    const filterTags = menuItem.filterTags ?? []

    const intersection = dietaryPreferences.filter((pref) =>
      filterTags.includes(pref),
    )

    return intersection.length === dietaryPreferences.length
  }
 
  // heaps more Lodash code was removed below here
}

Note that I had to edit out the React code (useCallback, useMemo) as I was moving this code from the client to the server however this is still seriously impressive.

Kind of amazed at how good this technology is.

It's going to replace jobs. It's that good.