Skip to content

Commit 1fc54a2

Browse files
committed
Refactored The Code
1 parent 581ef77 commit 1fc54a2

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

src/commands/search.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ func (cmd *SearchCmd) Run() (error) {
3434
)
3535

3636
// This Loop Will Check if the name of description has our search target
37-
for index := range jsonData.Items {
38-
item := jsonData.Items[index]
37+
for _, item := range jsonData.Items {
3938
item.Name = strings.ToLower(item.Name)
4039
item.Description = strings.ToLower(item.Description)
4140
if strings.Contains(item.Name, cmd.Name) || strings.Contains(item.Description, cmd.Name) {
@@ -72,10 +71,10 @@ func (cmd *SearchCmd) Run() (error) {
7271
if len(foundItems) == 0 {
7372
fmt.Println("Nothing Found in the catalog!")
7473
} else {
75-
for foundIndex := range foundItems {
76-
fmt.Println("\n" + foundItems[foundIndex].Name + " - " + foundItems[foundIndex].Links[0].Url)
77-
if foundItems[foundIndex].Description != "" {
78-
fmt.Println(" " + foundItems[foundIndex].Description)
74+
for _, foundItems := range foundItems {
75+
fmt.Println("\n" + foundItems.Name + " - " + foundItems.Links[0].Url)
76+
if foundItems.Description != "" {
77+
fmt.Println(" " + foundItems.Description)
7978
} else {
8079
fmt.Println(" No Description provided from Author!")
8180
}

0 commit comments

Comments
 (0)