Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions challenge-19/submissions/azs0309/solution-template.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package main

import (
"fmt"
)

func main() {
// Example slice for testing
numbers := []int{3, 1, 4, 1, 5, 9, 2, 6}

// Test FindMax
max := FindMax(numbers)
fmt.Printf("Maximum value: %d\n", max)

// Test RemoveDuplicates
unique := RemoveDuplicates(numbers)
fmt.Printf("After removing duplicates: %v\n", unique)

// Test ReverseSlice
reversed := ReverseSlice(numbers)
fmt.Printf("Reversed: %v\n", reversed)

// Test FilterEven
evenOnly := FilterEven(numbers)
fmt.Printf("Even numbers only: %v\n", evenOnly)
}

// FindMax returns the maximum value in a slice of integers.
// If the slice is empty, it returns 0.
func FindMax(numbers []int) int {
if len(numbers) == 0{
return 0
}
max := numbers[0]
for _ , number := range numbers[1:] {
if max < number{
max = number
}
}

return max
}

// RemoveDuplicates returns a new slice with duplicate values removed,
// preserving the original order of elements.
func RemoveDuplicates(numbers []int) []int {
if len(numbers) == 0{
return []int{}
}
result := make([]int,0,len(numbers))

result = append(result, numbers[0])
for _, number := range numbers {
found := false
for _, inresult := range result {
if number == inresult {
found = true
}
}
if !found {
result = append(result, number)
}
}
return result
}

// ReverseSlice returns a new slice with elements in reverse order.
func ReverseSlice(slice []int) []int {
if len(slice) == 0{
return []int{}
}
// if len(slice) == 1{
// return slice
// }
Comment on lines +72 to +74
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Remove commented-out code.

The commented lines are unnecessary dead code and should be removed to keep the codebase clean.

🔎 Proposed fix
     if len(slice) == 0{
 	 return []int{}
 	}
-// 	if len(slice) == 1{
-// 	 return slice
-// 	}
 	reversed := make([]int,0,len(slice))
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// if len(slice) == 1{
// return slice
// }
if len(slice) == 0{
return []int{}
}
reversed := make([]int,0,len(slice))
🤖 Prompt for AI Agents
In challenge-19/submissions/azs0309/solution-template.go around lines 72 to 74,
there are three commented-out lines (an if len(slice) == 1 check and return)
that are dead code; remove these commented lines entirely to clean up the file
and keep the codebase tidy, leaving no leftover commented logic.

reversed := make([]int,0,len(slice))
for i := len(slice)-1; i >= 0 ; i-- {
reversed = append(reversed,slice[i])
}
return reversed
}

// FilterEven returns a new slice containing only the even numbers
// from the original slice.
func FilterEven(numbers []int) []int {
if len(numbers) == 0{
return []int{}
}
filtered := make([]int,0)
for _, number := range numbers {
if number%2 == 0 {
filtered = append(filtered, number)
}
}
return filtered
}
Loading