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 trialTravis John Villanueva
5,052 PointsOverride Topic
I am a bit confuse with how the question are structured. Im clear with override, but integrating it with a class that has a empty array, i don't know if i would change the base class or create one myself in the subclass. Can anyone help me regarding this one?
namespace Treehouse.CodeChallenges
{
class SequenceDetector
{
public virtual bool Scan(int[] sequence)
{
return true;
}
}
}
namespace Treehouse.CodeChallenges
{
class RepeatDetector : SequenceDetector
{
public override bool Scan(int[] sequence)
{
int i=1;
int j = i-1;
while(i < sequence.Length){
if(sequence[i]==sequence[j]){
return true;
i++;
}
return false;
}
}
}
}
1 Answer
Steven Parker
231,198 PointsThis code looks awfully familiar.
Remember, 5 days ago in your other question I told you that you probably want to return false only after the loop is over. I also said that you should compute your "j" value inside the loop,
I see that you added an increment for "i", but it should not be inside the conditional. And nothing is ever executed after a return statement.
But as to your question, you won't need to create an array for this challenge. And neither of these classes has an empty array, but they both have a function that takes an array argument. That passed-in array is all you need to make the function work.