← Back to challenges

Longest Common Ending

JavaScriptHardstringsloops

Instructions

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.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.