+ 1

How to get an index of Array even if this index is greater than the Array length ?

I have in my code an Array of char that represents all the 10 numbers ( 1,2,3,4,5,6,7,8,9,0), and I want to get the number at index 24 for example. If I search the 13th slot, I want to get 3 in output. I'm looking for a function or formula witch works if I input 345 for example Thanks :)

21st May 2017, 11:06 AM
Ninja Nudiste
Ninja Nudiste - avatar
7 odpowiedzi
+ 5
wait .... what..... but there is nothing in those spots? its sorta like pulling a rabbit out of a hat but you forgot to put the rabbit up your sleave...
21st May 2017, 11:13 AM
jay
jay - avatar
+ 4
ummm ok. wierd. but ok
21st May 2017, 11:31 AM
jay
jay - avatar
+ 1
My code is a password encryption, that's why i need to loop into
21st May 2017, 11:32 AM
Ninja Nudiste
Ninja Nudiste - avatar
+ 1
hi, modify your array to begin with 0 and return value modulo 10 i put an example in ruby but it is easy to read arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] val = 24 puts arr[val%10] val = 20 puts arr[val%10] val = 345 puts arr[val%10]
21st May 2017, 12:00 PM
MBZH31
MBZH31 - avatar
0
The thing : I want to loop into the Array a x number of times to get a spot
21st May 2017, 11:29 AM
Ninja Nudiste
Ninja Nudiste - avatar
0
Oh un breton :D Merci !
21st May 2017, 1:09 PM
Ninja Nudiste
Ninja Nudiste - avatar
0
zut démasqué 😔
21st May 2017, 1:11 PM
MBZH31
MBZH31 - avatar