7 kyu

Is my string repeating the same character over and over ?

810 of 813ben8p

Description:

Your task is very simple:
Write a function hasOneChar returning:

  • true if the given string contains the same character repeated all along the string
  • false otherwise.

For instance:

hasOneChar('aaaaa'); //true
hasOneChar('aaaab'); //false
hasOneChar('bbbbb'); //true
hasOneChar('bbabb'); //false

Of course, what comes in mind first is a loop. But the purpose of this Kata is to test your creativity.
You have to achieve it without using any loops.

Corner cases: the function hasOneChar should return true if the string contains one single character.

Be creative!

Logic
Fundamentals

More By Author:

Check out these other kata created by ben8p

Stats:

CreatedDec 13, 2016
PublishedDec 13, 2016
Warriors Trained1446
Total Skips20
Total Code Submissions4665
Total Times Completed813
JavaScript Completions810
CoffeeScript Completions22
Total Stars10
% of votes with a positive feedback rating86% of 224
Total "Very Satisfied" Votes175
Total "Somewhat Satisfied" Votes35
Total "Not Satisfied" Votes14
Total Rank Assessments17
Average Assessed Rank
7 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • ben8p Avatar
  • Javatlacati Avatar
  • kazk Avatar
  • Voile Avatar
  • farhanaditya Avatar
Ad