S
S
Sedbol2020-05-06 08:59:14
JavaScript
Sedbol, 2020-05-06 08:59:14

Generate numbers from an array?

Take 15 numbers out of 36 numbers that are not in the array.
You need to take a combination of 15 numbers and form an array of them. The maximum number in the array should not exceed 36.

There is an array:

let arr=[
[1,3,4,5,2,6],
[8,9,10,12,11,13]
]

We need to get a new array of 15 numbers. In which there are no numbers from the array arr and each number does not exceed 36.

How to do this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav Boychenko, 2020-05-06
@Sedbol

We create an intermediate arr2 to store all the values ​​from the main array into it, and then we store in arr3 everything that is less than 37 and is not available in the general array.

let arr=[
[1,3,4,5,2,6],
[8,9,10,12,11,13]
]

let arr2 = [];
let arr3 = [];

for(let i = 0; i < arr.length; i++) {
  arr2 = [...arr2, ...arr[i]];
}

for(let k = 0; k < 37; k++) {
  if (!arr2.includes(k)) {
    arr3.push(k);
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question