N
N
Nastyuuuushka2016-07-04 11:23:57
Programming
Nastyuuuushka, 2016-07-04 11:23:57

A function that generates 5 random values ​​in a certain range without repetition. Explain the point?

Which lines contain a check for a mismatch of already existing values ​​in the array?
I don't understand how indexOf(value) < 0 works. I know that the indexOf object determines the order in the array, but why " < 0 " ?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander Manakov, 2016-07-04
@gogolor

If indexOf does not find an element in the array, then it returns -1
. For example, [1,2,3].indexOf(3) will return 2, and [1,2,3].indexOf(4) will return -1

A
Anton Fedoryan, 2016-07-04
@AnnTHony

The indexOf() method returns the first index by which the given element can be found in the array, or -1 if there is no such index.

Maybe try a little... think?
A random number is generated, if it is not in the array, then it is added, as indicated by the index -1

D
Dmitry Belyaev, 2016-07-04
@bingo347

Here you read a question in the list, look at its tags... you expect that now you will help a person with a tricky task to apply the Bloom filter... you open it, you spit with relish in disgust... and throw a link in response without going into details...
https://developer.mozilla.org/ru/docs/Web/JavaScri...
and ask Google to unban you from the search engine

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question