← Back to challenges

Neighboring Letters

JavaScriptHardhigher_order_functionslanguage_fundamentalsformattingloopsvalidation

Instructions

Create a function that takes a string and checks if every single character is preceded and followed by a character adjacent to it in the english alphabet.

Example: "b" should be preceded and followed by ether "a" or "c" (abc || cba || aba || cbc == true but abf || zbc == false).

Examples

neighboring("aba") ➞ true

neighboring("abcdedcba") ➞ true

neighboring("efghihfe") ➞ false

neighboring("abc") ➞ true

neighboring("qrstuv") ➞ true

neighboring("mnopqrstsrqponm") ➞ false

Notes

All test cases will consist of lower case letters only.

javascript
Loading editor…
⌘ ↡ to run
Walks through the solution with reasoning and edge cases.
Next: Plant Trees 🌲 β†’