Shortest code : Balance Attraction
Description:
Shortest code : Balance Attraction
(Code length limit: 200 chars)
This is the challenge version of coding three minutes series. If you feel difficult, please complete the simple version
Task
Insert some characters into a string, if there are the same characters in the string, they attract each other.
sc("abc",["b"]) === "abbc"
If there are two or more parts in a string, both have the same character. Character will be added to the shorter character chain.
sc("abbbab",["b"]) === "abbbabb"
sc("ababbb",["b"]) === "abbabbb"
If there are two or more parts in a string, both have the same character, and chains have same length. Character will be added to the left one.
sc("ababab",["b"]) === "abbabab"
If there is no same character in the string, add character to the end of string.
sc("ab",["c"]) === "abc"
input: string str
, string array chars
,insert chars
into str
, str and char range is a-z.
output: the str
after insert chars
Code length calculation
In javascript, we can't get the user's real code, we can only get the system compiled code. Code length calculation is based the compiled code.
For example:
If you typed sc=x=>x+1
after compile, it will be:sc=function(x){return x+1;}
Series
- Bug in Apple
- Father and Son
- Jumping Dutch act
- Planting Trees
- Reading a Book
- Eat watermelon
- Special factor
- Symmetric Sort
- Are they symmetrical?
- Guess the Hat
- Find the murderer
- Give me the equation
- Balance Attraction
- Max Value
- Regular expression compression
- Remove screws I
- Remove screws II
- Collatz Array(Split or merge)
- Trypophobia
- Virus in Apple
- Waiting for a Bus
- Tidy up the room
Similar Kata:
Stats:
Created | Apr 3, 2016 |
Published | Apr 5, 2016 |
Warriors Trained | 275 |
Total Skips | 16 |
Total Code Submissions | 1179 |
Total Times Completed | 63 |
JavaScript Completions | 63 |
Total Stars | 8 |
% of votes with a positive feedback rating | 92% of 33 |
Total "Very Satisfied" Votes | 29 |
Total "Somewhat Satisfied" Votes | 3 |
Total "Not Satisfied" Votes | 1 |
Total Rank Assessments | 5 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 6 kyu |