Longest Common Ending

Published by Matt in

Write a function that returns the longest common ending between two strings.

Examples

longestCommonEnding("multiplication", "ration") ➞ "ation"

longestCommonEnding("potent", "tent") ➞ "tent"

longestCommonEnding("skyscraper", "carnivore") ➞ ""

Notes

Return an empty string if there exists no common ending.

Watch a quick demo on how Edabit works.