Majority function added with tests