Solución
solution.tsTypeScript
type IsPure = { deterministic: boolean; noMutation: boolean };
function double(x: number): number { return x * 2; }
function pureMap(arr: number[]): number[] { return arr.map(x => x * 2); }
// Implementa verifyPurity:
// deterministic: ¿double(5) === double(5)?
// noMutation: después de pureMap(arr), ¿arr sigue siendo [1,2,3]?
function verifyPurity(): IsPure {
// Tu código aquí
const firstReturn = double(5);
const secondReturn = double(5);
const isDoubleDeterministic: boolean = firstReturn === secondReturn;
//
const arrArgument = [1, 2, 3];
const arrArgumentCopy = [...arrArgument];
// Ejecuta pureMap con el arreglo de prueba:
pureMap( arrArgument );
// Comprueba que todos los elementos del arreglo de prueba original son iguales
// a su copia antes de llamar a pureMap()
const isNoMutated: boolean = arrArgument.every( (num: number, index: number) => {
return num === arrArgumentCopy[index];
}
);
return { deterministic: isDoubleDeterministic, noMutation: isNoMutated };
}
export { verifyPurity };0respuestas