+ 1

Code Coach “Tax Free” (Medium) C# functional approach - room for improvement?

The solution to the Tax Free problem (medium difficulty in Code Coach) can be condensed down to a single line. I guess it’s not the most readable code, but still
 Any room for improvement? https://code.sololearn.com/cFGY1h1oNC3m/?ref=app

13th Jul 2022, 1:43 PM
complexcity
10 Respostas
+ 1
Do you have a question?
13th Jul 2022, 2:03 PM
Jayakrishna 🇼🇳
+ 1
I mean, Your code has only 3 steps splitting and mapping, then find sum. Still improvement means can be reduce of line characters. It don't have difference in performance. This way it can be , but no difference much as far I know: Console.Write( Console.ReadLine().Split(',').Select(x => Convert. ToDouble(x)<20 ? double.Parse(x)*1.07 : double.Parse(x)).Sum()); Ok. Let me see others suggestions about improvements.. So I also start understand basics of FP.............
13th Jul 2022, 4:50 PM
Jayakrishna 🇼🇳
+ 1
Btw I didn't tho that would even Work but I tested: Console.Write( Console.ReadLine().Split(',') .select((double)x => x<20? x*1.07 : x).Sum()); Unexpecting I got Error ',' Missing x2. Why?
13th Jul 2022, 5:35 PM
Felix Alcor
Felix Alcor - avatar
+ 1
Felix Alcor 'x' is a string there so casting (double)x don't work. You need a parsing method... double.Parse(x) or Convert.ToDouble(x); And use Capital S in select.
13th Jul 2022, 6:51 PM
Jayakrishna 🇼🇳
+ 1
Jayakrishna🇼🇳 (double) can be used to give a Type to some Not directly declared variables. But nether that or capital letters was what I meant. No matter if I use my Methode or yours both give out Missing ',' and I want ro know where the missed ',' came from.
13th Jul 2022, 7:35 PM
Felix Alcor
Felix Alcor - avatar
+ 1
Felix Alcor I think ' select {value} ' according to syntax it's expecting a camma after (double) x, not a lambda expression. Do you have any correct working code sample as you expecting..?
13th Jul 2022, 8:08 PM
Jayakrishna 🇼🇳
+ 1
Jayakrishna🇼🇳 Yeah I guess so to but without '=>' does it not work. I only wanted to do that because I hate making so many convert for the same value, so now I got around it with a Method. https://code.sololearn.com/c6JxYEHqdLzS/?ref=app
13th Jul 2022, 8:53 PM
Felix Alcor
Felix Alcor - avatar
0
Jayakrishna🇼🇳 I think his question is what He can improve there
13th Jul 2022, 3:45 PM
Felix Alcor
Felix Alcor - avatar
0
Felix Alcor That's "any improvement" is added after my reply.. complexcity So in that case, it can be suits best on feed post. No improvement is actually need there I think. Sharing Code coach solutions are also is a spoiler alert.. Others just use to get xp, instead of their own try...
13th Jul 2022, 3:55 PM
Jayakrishna 🇼🇳
0
I think functional programming is probably not the first thing you learn, and in my experience you need to understand the basics first, otherwise it doesn’t make sense.
13th Jul 2022, 4:17 PM
complexcity