Decrypt one level of a generic object without compromising on it's structure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type IData = { [keys: string]: number }; | |
const encrypted1: IData = { | |
a: 10, | |
b: 20, | |
c: 30, | |
}; | |
const encrypted2: IData = { | |
d: 40, | |
e: 50, | |
f: 60, | |
}; | |
function decrypt(data: IData): IData { | |
const result: IData = {}; | |
for (const key in data) { | |
if (Object.prototype.hasOwnProperty.call(data, key)) { | |
// custom decryption step | |
const decrypting = data[key] / 10; | |
result[key] = decrypting; | |
} | |
} | |
return result; | |
} | |
const decrypted1: IData = decrypt(encrypted1); | |
decrypted1; // { a: 1, b: 2, c: 3 } | |
const decrypted2: IData = decrypt(encrypted2); | |
decrypted2; // { d: 4, e: 5, f: 6 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment