The Daily WTF
Russell F sends us this C# fuction, and I have to be honest: I have no idea what it’s supposed to do. I can trace through the logic, I can see what it does, but I don’t understand why it does it.
private List<LaborService> Tranpose(List<LaborService> laborService) { int half = (int)Math.Ceiling((decimal)(laborService.Count)/2); for (int i = 0; i < laborService.Count; i++) { if (i < half) laborService[i].Order = 2 * i; else laborService[i].Order = (i – half) + 1; } return laborService.OrderBy(x => x.Order).ToList(); }
So this starts by finding the rough midpoint of our list. Then we iterate across each element, and if it’s position is less than half, we place double its index into the Order field. If it’s half or greater, we store its index minus half, plus one, into its order field. Finally, we sort by Order.
Now, based on the name, we can assume this
To read the full article click on the 'post' link at the top.