simple-exercises/ruby-exercises/easy-8.rb
# One-week Wonders
# ------------------------------------------------------------------------------
# Given a list of songs at the top of the charts, return the songs that only
# stayed on the chart for a week at a time.
#
# Songs CAN reappear on the chart, as long as it's for a week at a time. Only
# count those songs once.
#
# Suggested strategy: find the songs that show up multiple times in a row and
# subtract them out.
One-week Wonders
Given a list of songs at the top of the charts, return the songs that only
stayed on the chart for a week at a time.

Songs CAN reappear on the chart, as long as it's for a week at a time. Only
count those songs once.

Suggested strategy: find the songs that show up multiple times in a row and
subtract them out.
One - week Wonders Given a list of songs at the top of the charts return the songs that only stayed on the chart for a week at a time . Songs CAN reappear on the chart as long as it ' s for a week at a time . Only count those songs once . Suggested strategy : find the songs that show up multiple times in a row and subtract them out .
def one_week_wonders(songs)
  wonders = []
  (1...(songs.length - 1).each do |i|
    if songs[i - 1] == songs[i] or songs[i] == songs[i + 1]
      if !not_wonders.include?(songs[i])
        not_wonders << songs[i]
      end
    end
  end
  wonders = []
  songs.each do |song|
    if !not_wonders.include?(song) and !wonders.include?(song)
      wonders << song
    end
  end
  wonders
end
def one_week_wonders ( songs ) wonders = [ ] ( 1 ... ( songs . length - 1 ) . each do | i | if songs [ i - 1 ] == songs [ i ] or songs [ i ] == songs [ i + 1 ] if ! not_wonders . include? ( songs [ i ] ) not_wonders << songs [ i ] end end end wonders = [ ] songs . each do | song | if ! not_wonders . include? ( song ) and ! wonders . include? ( song ) wonders << song end end wonders end
One-week Wonders
Given a list of songs at the top of the charts, return the songs that only
stayed on the chart for a week at a time.
One - week Wonders Given a list of songs at the top of the charts return the songs that only stayed on the chart for a week at a time .
# two conditions must be satisfied # for it NOT to be a one week wonder # song this week is the song from previous week # or song this week is the song next week # if it's already in the not wonders, lets not repear ourselves # if it is not in the not_wonders list then it is a wonder # we should add a song that is already in the wonders list
songs
<not_specific>