Thread: Help Array!!!!!
View Single Post
Old 12-31-2012, 04:48 AM   PM User | #17
Logic Ali
Regular Coder

 
Logic Ali's Avatar
 
Join Date: Sep 2010
Location: London
Posts: 959
Thanks: 0
Thanked 198 Times in 193 Posts
Logic Ali will become famous soon enoughLogic Ali will become famous soon enough
Quote:
Originally Posted by jmrker View Post
And adding to 'Logic Ali's brilliant code ...
Code:
<script type="text/javascript">

array1 = [ 1, 4, 2, 13, 5 ];

odds = array1.slice( 0 ).filter( function( elem ){ return elem % 2; } )
evens = array1.slice( 0 ).filter( function( elem ){ return elem%2==0; } )

alert( odds + '\n\n' + evens );

</script>
Actually I should have remembered that .slice is unnecessary with .filter.
Logic Ali is online now   Reply With Quote