Tuesday, August 2, 2016

Code Test

I had a C# question a couple of weeks ago:  Print all of the even numbers in an int array.

(new[] { 1, 5, 6, 8, 33, 15, 212, 432, 244224, 131, 33225, 888, 64, 89, 101 })
.Where(x => x % 2 == 0)
.ToList()
.ForEach(x => Console.WriteLine(x));

In js it's even easier:

[1, 5, 6, 8, 33, 15, 212, 432, 244224, 131, 33225, 888, 64, 89, 101 ].filter((el) => (el % 2 == 0)).forEach(el => console.log(el))

No comments:

Post a Comment