Answer the question
In order to leave comments, you need to log in
How to convert this array in 13 steps?
here the array [2,3,3,5,5,5,4,12,12,10,15] must be converted in 13 steps to [2,3,4,5,6,7,8,9,10, 11.12]
function solution(x){
let count = 0;
for(let i = 0 ; i < x.length;i++){
if(x[i] > x[i + 1]){
x[i + 1] = x[i] + 1
count++
console.log(x)
}
if(x[i] < x[i + 1]){
x[i + 1] = x[i] + 1
count++
}
console.log(x)
if(x[i] >= x[i + 1]){
x[i + 1] = x[i] + 1
count++
}
console.log(count)
}
}
console.log(solution([2,3,3,5,5,5,4,12,12,10,15]))
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question