Finding Duplicate CSharp
Finding Duplicate: A TDD Exercise
The problem
Given an integer array of any size, we need to find if it contains duplicate elements or not, without using any built-in functions specifically for that and also by not using any data structures other than arrays!
Approach using TDD
Start with a small and naive failing test, say for just 2 elements
Code just enough to pass it
Refactor if you can
Move ahead with a less naive failing test, this time with 3 elements
Code just enough to pass it
Refactor
Repeat the same until most non-trivial cases with more elements are passing. Once we have enough cases, we could also see at improving the code or doing it in more efficient ways!
Some snippets to get you started
Snippet 1
Snippet 2
Snippet 3
Do you see any issue with above code? :O
Exercise: Try this out by using the partially completed solution:
Last updated