Mercurial > projects > dynamin
view dynamin/core/array.d @ 111:8ba1044adc93
Rename Newline.Macintosh/Linux to better names.
CR is not used on Mac since before OS X. And LF is not just used on
Linux, but other Unix systems too.
author | Jordan Miner <jminer7@gmail.com> |
---|---|
date | Sat, 19 Jan 2013 20:57:11 -0600 |
parents | 73060bc3f004 |
children | 4636a64afabc |
line wrap: on
line source
/* * Copyright Jordan Miner * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file BOOST_LICENSE.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) * */ module dynamin.core.array; /** * Tests whether or not the specified item is in the specified array. * Returns: true if the specified item is in the array and false otherwise * Examples: * ----- * "Hello".contains('e') == true * "Hello".contains('a') == false * "".contains('e') == false * assert([2, 3, 7].contains(3) == true); * assert([2, 3, 7].contains(0) == false); * ----- */ bool contains(T, U)(T[] arr, U item) { foreach(U item2; arr) { if(item == item2) return true; } return false; } unittest { assert("Hello".contains('e') == true); assert("Hello".contains('a') == false); assert("".contains('e') == false); assert([2, 3, 7].contains(3) == true); assert([2, 3, 7].contains(0) == false); }