D
D
dfymrf32021-06-21 16:10:55
JavaScript
dfymrf3, 2021-06-21 16:10:55

Why does it give 5 answers, and how can I do either yes or no? Need to find out if there is one number 2 times in a row. And print yes or no?

let arr = [1, 2, 6, 6, 7, 8];
for (let i = 0, j = i + 1; i < arr.length, j < arr.length; i++, j++) {
if (arr[i] === arr[j]) {
console.log(" da");

} else {
console.log("Net");
}
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2021-06-22
@Seasle

const result = arr.some((value, index, array) => value === array[index + 1]);
console.log(result ? 'Да' : 'Нет');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question