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 trialTiago Ramos
2,380 PointsHow to check if any value of the array is a repeat of preceding value?
Hi guys,
I have an idea, but tell me if there is a better way, I think I should: 1 - make a foreach loop to iterate the array 2 - during the iteration compare the actual value with the previous one 3 - return true if the value it's the same
Thanks guys :)
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)
{
// use a foreach loop
// comparing the actual value in the array with the previous one
// return true if it is the same
return true;
}
}
}
1 Answer
Steven Parker
231,269 PointsIt sounds like you have a good idea. It should pass the challenge when correctly implemented.
Remember to return "false" if the loop finishes.