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 trialChristian Grosskopf
23,906 PointsCan't figure out how to set up the method in this code challenge
Override the Scan method to return true if any value in the array is a repeat of the value immediately preceding it.
namespace Treehouse.CodeChallenges
{
class RepeatDetector : SequenceDetector
{
public override bool Scan(int[] sequence)
if()
{
}
}
}
1 Answer
Steven Thacher
3,548 PointsAre you having issues with the overriding itself? Or just writing the logic in the method?
In a case like this, I'd iterate through each value in 'sequence' starting at index 1 (not 0), and check if sequence[i - 1] == sequence[i]
eg. for (int i = 1; i < sequence.Length; i++) { if (sequence[i - 1] == sequence[i] return true; }
return false;
Jason Anders
Treehouse Moderator 145,860 PointsJason Anders
Treehouse Moderator 145,860 PointsHey Christian,
Could you please provide the link to the actual challenge. It'll make for much more accurate and easier assistance. Thanks :)