Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR RUBY

each_cons with index ruby

['a', 'b', 'c', 'd', 'e'].each_cons(3).to_a.each_with_index {|(previous, current, nekst), i|
    puts "#{i + 1}. #{previous} - #{current} - #{nekst}"
}

#returns consective elements with their indexes


####################Another way can be this#################

['a', 'b', 'c', 'd', 'e'].each_cons(3).with_index{|array_3,index| p a; p b}
 
PREVIOUS NEXT
Tagged: #index #ruby
ADD COMMENT
Topic
Name
1+7 =