To find the repetitive number and remove it, we can follow these steps:
1. Create a uint array
2. Create a write function. The algorithm is, we will compare each number to the number on its right. To make this
possible, we will use two for loops. First for loop, will store the number on the left and this for loop will be the parent for loop.
The second for loop will bring all numbers on the right of first number. It will then compare each number
(the numbers brought by second for loop) to the first loop number.
3. Inside our second (child) for loop, there will be an if statement to detect if the first number is equal to second number.
If same, then it will replace it with the element at the end of our array.
4. Later we can remove the last element by using "pop()". We will see that the order will be broken, but in any case it will be a solution
to what we want to do.
5. Lastly we will create a view function, to see our uint array.
6. You can copy-paste this to
Remix, and play with it to practice and learn.
Click on arrows for the next Article: ⇨ ⇨