find missing element in an array

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 15 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
migreene
Posts: 11
Last visit: Sun Aug 09, 2009 11:26 pm

find missing element in an array

Post by migreene »

Here's a problem I'm working on, maybe one of you would like the challenge. I need to find the missing number in an array that looks like:
01, 02, 03, 05, 06, 07
script should return 4

The challenge is the array may sometimes be null, and also may sometimes have only 1 element thus becoming a two character string.
User avatar
migreene
Posts: 11
Last visit: Sun Aug 09, 2009 11:26 pm

find missing element in an array

Post by migreene »

Here's a problem I'm working on, maybe one of you would like the challenge. I need to find the missing number in an array that looks like:
01, 02, 03, 05, 06, 07
script should return 4

The challenge is the array may sometimes be null, and also may sometimes have only 1 element thus becoming a two character string.
User avatar
migreene
Posts: 11
Last visit: Sun Aug 09, 2009 11:26 pm

find missing element in an array

Post by migreene »

Forgot to add, the difference between the numbers may be greater than 1 such as
01, 02, 06, 07

but I'm always looking for the lowest missing number.
User avatar
jhicks
Posts: 1789
Last visit: Mon Oct 19, 2015 9:21 am

find missing element in an array

Post by jhicks »

Will the array always start at 1? Is it possible that the array could start at 2?
This topic is 15 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked