Answer the question
In order to leave comments, you need to log in
Why can't the array be sorted?
There is an array of type Item:
type Item struct {
Title string `xml:"title"`
Link string `xml:"link"`
Description string `xml:"description"`
Date string `xml:"pubDate"`
}
"Sat, 18 Feb 2017 16:40:05 +0300"
func sortNews(feeds []Item) []Item {
length := len(feeds)
for i := 0; i < length-1; i++ {
oneDate, _ := time.Parse(time.RFC1123Z, feeds[i].Date)
for j := i+1; j < length; j++ {
nextDate, _ := time.Parse(time.RFC1123Z, feeds[j].Date)
b := nextDate.Before(oneDate)
if b {
trash := feeds[i].Date
feeds[i].Date = feeds[j].Date
feeds[j].Date = trash
}
}
}
return feeds
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question