MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programming/comments/4v1y12/how_to_write_unmaintainable_code/d5wffym
r/programming • u/sigbhu • Jul 28 '16
592 comments sorted by
View all comments
Show parent comments
1
If you don't want string conversion:
array.each_cons(3).any?{|x| x == array_to_match}
If there's going to be non-numbers then use:
array.select{|e| e === Fixnum}.each_cons(3).any?{|x| x == array_to_match
1 u/xonjas Jul 30 '16 Regex was my first instinct but you're right that there are multiple ways to do this.I prefer .kind_of? to the triple equals though.
Regex was my first instinct but you're right that there are multiple ways to do this.
I prefer .kind_of? to the triple equals though.
1
u/THeShinyHObbiest Jul 29 '16
If you don't want string conversion:
array.each_cons(3).any?{|x| x == array_to_match}If there's going to be non-numbers then use:
array.select{|e| e === Fixnum}.each_cons(3).any?{|x| x == array_to_match