In my scenario, I am dealing with text input elements that contain the starting time for a person's shift (e.g. 9:00, 9:30, 10:00, etc).
My approach involves iterating through these elements one by one and storing them in an array. If a particular value already exists in the array, I need to increment the time by 15 minutes (0.15) and check again if it exists. This process will continue until a unique value is found and added to the array.
For instance: John - 9:00 Bill - 9:00 Julie - 9:30 Sam - 9:30 Tony - 9:30
times = []
The first time encountered is 9:00, which is not present in times, so it gets added. The updated times array becomes [9]. Next is another 9:00, which does exist, hence 0.15 is added, resulting in 9.15. Since this new value is unique, it is included in the times array as well. This cycle repeats for all elements. If the minute component reaches .60, an hour needs to be incremented by 1. For example, Tony's time would become 10.
Although I could use an if statement to perform this once, how can I iteratively add 15 minutes and repeatedly check multiple times without using numerous if statements?
if( times.contains(value)) {
times.push(value + 0.15)
}
If I were to follow the above approach, it would require countless if statements. Is there a more efficient way to continuously check and terminate the loop immediately after adding a unique value?