We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Plus Minus
- Discussions
Plus Minus
Plus Minus
Sort by
recency
|
693 Discussions
|
Please Login in order to post a comment
Depending on the size of the dataset, it can use CompletableFuture or even a ThreadPool (in C# TPL for async and parallel tasks as well). But this task is quite simple, so it would not be required
public static void plusMinus(List arr) { var total = arr.Count(); var positives = arr.Where(p => p > 0).ToList(); Console.WriteLine(CalculateInputRatio(positives.Count, total));
let final ={p:0,n:0,z:0}; for(let i of arr){ if(i===0){ final['z']=(final['z']||0) +1; } if(i<0){ final['n']=(final['n']||0) +1; } if(i>0){ final['p']=(final['p']||0) +1; } } Object.values(final).map(item=>console.log(item/arr.length))