tags:

views:

28

answers:

2

given:

var args = new string[] { "-one",  "two",  "three",  "-four" };

what would magic function need to look like in order to make the following pass?

var result = MagicFunction(args);
Assert.AreEqual(0, result[0]);
Assert.AreEqual(3, result[1]);
Assert.AreEqual(2, result.Length);
A: 

It looks like prototype can do it for you: http://www.prototypejs.org/api/enumerable/find

Chris
Oh, maybe not: it looked like JS but tags say C#
Chris
+2  A: 
int[] MagicFunction(string[] args)
{
    return args.Select((s, i) => new { Value = s, Index = i }) // Associate an index to each item
               .Where(o => o.Value.StartsWith("-"))            // Filter the values
               .Select(o => o.Index)                           // Select the index
               .ToArray();                                     // Convert to array
}
Thomas Levesque
thanks, the first select was jamming me up.
TheDeeno