Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Yet when you try to access the property:
'Kata' does not contain a definition for 'Firstname'
Capitalizing the N in name seems to work (just for
FirstName
,Surname
is correct apparently). Please fix the comments so we don't have to waste time guessing at someone's property naming style, and fix the partial class to use consitent naming.I don't think there's anything wrong with condensing code, especially when you are taking advantage of language features, as long as what you're doing in the condensing isn't incredibly difficult. Writing code vertically helps when debugging, and there is absolutely nothing wrong with it. When you're writing quite a lot of code, or repetitive code, sometimes you decide to use the languages features to save you time/gain performance. I would think by this time you have an understanding of the underlying concepts (reference vs value, heap vs stack, classes, pointers, interfaces, etc) which allow you to do more complicated things in shorter amount of lines (although line counts are a bad metric to measure performance or elegance!)
To me, the following is reasonable and readable.
This comment is hidden because it contains spoiler information about the solution
Why is it outside of your control? Is the setup.cs file something that CodeWars maintains?
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
.ToList() converts your array from one IEnumerable to another IEnumerable. .Select() iterates over each object in the IEnumerable collection, .Where() then filters every one of those items, and .Sum() iterates through the now filtered ones and sums it up. You're iterating through the collection 4 times, rather inefficient.
Since T[] implements IEnumerable, you can use Linq directly off it. So arr.Where(x => x > 0).Sum() would cut the number of iterations in half. Also, since 0 doesn't do anything to your sum, leaving it out could reduce the number of values Sum needs to operate on.
Just some food for thought.
This comment is hidden because it contains spoiler information about the solution