Skip to content

Instantly share code, notes, and snippets.

@ohmslaw
Last active March 9, 2016 22:31
Show Gist options
  • Save ohmslaw/18881b304358b4f10f80 to your computer and use it in GitHub Desktop.
Save ohmslaw/18881b304358b4f10f80 to your computer and use it in GitHub Desktop.
Coding Problems - Alphabetical center
/**
* Simple Text: Write a method in which provided two strings, it returns a string between them. Additionally, a
* percentage will be provided to allow us to fine-tune the outcome.
*
* Nerd Text: Given two strings A & B where 'a' <= A <= B <= 'z' and a skew N where 0 <= N <= 1. Write a method that
* returns a value X where A <= X <= B relative to N. The intent of the skew is to dictate where X should fall between
* A & B. Meaning X will not always be exactly halfway between.
*
* Caveats:
* - The examples below treat N as a linear value so your results might be different. This is acceptable as long as
* the general concept is followed.
* - Shorter the string the better, we are not looking for a true midpoint of two strings.
*/
// Examples:
alphabetical('a', 'a'){ … }; // return 'a'
alphabetical('a', 'e', 0.5){ … }; // return 'c'
alphabetical('a', 'e', 0.8){ … }; // return 'd'
alphabetical('aaa', 'ccc'){ … }; // return 'b'
alphabetical('aa', 'ac'){ … }; // return 'ab'
alphabetical('aaa', 'aac'){ … }; // return 'aab'
alphabetical('aa', 'ab'){ … }; // return 'aam'
alphabetical('aabb', 'aacc'){ … }; // return 'aac'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment