Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

Ruby/RoR - Count occurrence of an element in an array -


i'v hash

{1=>true, 7=>false, 6=>true, 4=>false}

or array

[1, true], [7, false], [6, true], [4, false]]

or

[true, false, true, false].

how can find number of trues in array?

in order count elements, have iterate on collection. since iterating on hash yields two-element arrays, first 2 same:

{ 1 => true, 7 => false, 6 => true, 4 => false }.count(&:last) [[1, true], [7, false], [6, true], [4, false]].count(&:last) 

for simple array case, this:

[true, false, true, false].count(true) 

this array of course same hash#values hash above, use same method on that:

{ 1 => true, 7 => false, 6 => true, 4 => false }.values.count(true) 

if don't know 1 of 3 get, use this:

{ 1 => true, 7 => false, 6 => true, 4 => false }.flatten.count(true) [[1, true], [7, false], [6, true], [4, false]].flatten.count(true) [true, false, true, false].flatten.count(true) 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -