November 04, 2015
On Tuesday, 3 November 2015 at 15:06:00 UTC, Namal wrote:
>>Can you help me out please. Thx.

reduce!((x, y) => x + !y)(0, arr).writeln;

This would probably be the preferred way, that uses a lambda function (x, y) => x + !y which adds the inverse of the next array value (y) to the total so far (x). You have to provide 0 as the first argument to reduce as it is the seed, otherwise it will use the first value in the array as the seed and convert it to an int, making the total 1 too high as the first value is 'true'.

You can also use a string but this is frowned on style-wise though in this case it is clearer:

reduce!"a + !b"(0, arr).writeln;
1 2 3
Next ›   Last »