Pergunta de entrevista da empresa Persistent Systems

There are an array given if i would add one number in the last index then second array element should be change Example: Input = [7,8,9] Result= [7,9,0] Input = [7,9,9] , Result= [ 8, 0, 0 ]

Resposta da entrevista

Sigiloso

6 de ago. de 2025

_array = [7,9,9]; j=0; stringLength = 0; addition = 1; for (let i=_array.length-1;i>=0;i--){ // if(j == 0){ tmp = _array[i]+addition; stringIndex = tmp.toString().split(''); stringLength = stringIndex.length; // } if(stringLength == 2){ addition = parseInt(stringIndex[0]); _array[i] = parseInt(stringIndex[1]); } else{ _array[i] = tmp; addition=0; } j++; }