|
|
![]() |
| Thread Tools | Search this Thread |
#1
| |||
| |||
Counting numbers and deleting array I am trying to delete an element from an array if it exists and count the number of item afterwards I wrote Code: anArray = [1,2,3,4,5,6,7,8,9] anArray.size => 9 anArray.map {|e| e if e != 4}.compact => [1, 2, 3, 5, 6, 7, 8, 9] anArray.map {|e| e if e != 4}.compact.size => 8 Thanks |
#2
| |||
| |||
How about using Array#delete_if? |
#3
| |||
| |||
Array#delete works also with no need for a block (i.e. you're only checking for equality) anArray = [1,2,3,4,5,6] p anArray.delete(4) p anArray.size |
![]() |
|
Tags: array, counting, deleting, numbers |
Thread Tools | Search this Thread |
|
![]() | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to change negative numbers to positive numbers in Excel | Shaina Na | Microsoft Project | 3 | 08-01-2012 05:35 PM |
Need C program code to count numbers of negative & positive numbers | Sarfaraj Khan | Software Development | 5 | 16-01-2010 02:00 PM |
Want an array of Random numbers | InterNetWorKed | Software Development | 4 | 03-11-2009 02:17 PM |
Loop counting odd and even numbers | Allan.d | Software Development | 3 | 23-10-2009 11:40 AM |
SQL Query for Searching Missing Numbers from Sequence of Numbers | Bhagwandas | Software Development | 3 | 18-02-2009 01:47 PM |