Solución
solution.tsTypeScript
export function removeConsecutiveDuplicates(numbers: number[]): number[] {
// Usa while para recorrer el array y eliminar duplicados consecutivos
const withoutDuplicates: number[] = [];
let index = 0;
while ( index < numbers.length ) {
// Podría dar lugar a 'undefined' al llegar al último número
// if( numbers[index] === numbers [index + 1]) {
if(withoutDuplicates.length === 0 || numbers[index] !== withoutDuplicates[withoutDuplicates.length - 1]) {
withoutDuplicates.push( numbers[index] );
}
index++;
}
return withoutDuplicates;
}
0respuestas