Login
|
Signup
langref.org
-
ruby
add..
all
clojure
cpp
csharp
erlang
fantom
fsharp
go
groovy
haskell
java
ocaml
perl
php
python
scala
Home
All
Solved
Unsolved
Strings
Numbers
Regex
Lists
Maps
Structure
Files
Dates
OOP
Networking
XML
Algorithms
Misc
Parallel
View Problem
Lists
Manipulation
Split a list of things into numbers and non-numbers
Given a list that might contain e.g. a string, an integer, a float and a date,
split the list into numbers and non-numbers.
ruby
now=Time.now
things=["hello", 25, 3.14, now]
numbers=things.select{|i| i.is_a? Numeric}
others=things-numbers
now=Time.now
things=["hello", 25, 3.14, now]
numbers=things.select{|i| i.is_a? Numeric}
others=things-numbers
ruby
now=Time.now
things=["hello", 25, 3.14, now]
numbers, others=things.partition{|i| i.is_a? Numeric}
now=Time.now
things=["hello", 25, 3.14, now]
numbers, others=things.partition{|i| i.is_a? Numeric}
Submit a new solution for
ruby
There are 18 other solutions in
additional
languages (
clojure
,
cpp
,
csharp
,
erlang
...)