Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialErik Hainer
3,049 PointsNo errors, but now It says it doesn't detect repetitions.
It just doesn't do what it's supposed to now.
namespace Treehouse.CodeChallenges
{
public class SequenceDetector
{
public virtual bool Scan(int[] sequence)
{
return true;
}
}
}
namespace Treehouse.CodeChallenges
{
public class RepeatDetector : SequenceDetector
{
public override bool Scan(int[] sequence)
{
for(int i=0;i<sequence.Length;i++)
{
if (i > 0)
{
if (sequence[i] == (sequence[i]- 1))
{
return true;
}
}
}
return false;
}
}
}
1 Answer
Steven Parker
231,268 PointsIt looks like you may have placed a bracket in the wrong place. The comparison sequence[i] == (sequence[i]- 1)
doesn't compare two different array elements, it compares each element's value with the result of subtracting one from itself (which can never be true).
You probably intended to write sequence[i] == sequence[i - 1]
instead.