Plan and done for Oct-06-2018
What will I learn today?
Keep solving and submitting CodeWars assignments.
Done
Solved reverse or rotate assignment and the most interesting as always - what is considered as best practice and clever solution by other members. The give solution is definitely clever and declarative (I strive to be as declarative as I can) and I've learned some stuff from it.
- Dividing integer by integer in C# you'll get an integer and never a float/double/decimal. No decimal delimiter! Never. No need for
Math.roundorMath.floor. Short SO explanation. - There is an
Enumerable.Range(). It works almost likerange()in Python:string.Join(",", Enumerable.Range(1,5))will produce "1,2,3,4,5". Almost like Python but not exactly because in Python the upper bound isn't included in the result, and we have additional method overload with a third parameter as step for generating the sequence. - There are two versions of
Reverse()method: one is forListcollection, another is for objects withIEnumerableimplemented. First is in place, second returnsIEnumerablecompatible. The reasons are historical. For strings we can use both, but the second seems more declarative.
char[] charArray = chunk.ToCharArray(); Array.Reverse( charArray ); string result = new string( charArray );
string result = new string(chunk.Reverse().ToArray());