← Back to challenges

In the Centre?

JavaScriptHardstringsvalidation

Instructions

Given a string containing mostly spaces and one non-space character, return whether the character is positioned in the very centre of the string. This means the number of spaces on both sides should be the same.

Examples

isCentral("  #  ") ➞ true

isCentral(" 2    ") ➞ false

isCentral("@") ➞ true

Notes

Only one character other than spaces will be given at a time.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: What's the Data Type?