Skip to content

Instantly share code, notes, and snippets.

@YodaLightsabr
Last active September 24, 2022 23:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YodaLightsabr/a4924816e0c7bd45b15d1c8aebfc582a to your computer and use it in GitHub Desktop.
Save YodaLightsabr/a4924816e0c7bd45b15d1c8aebfc582a to your computer and use it in GitHub Desktop.
Calculate how true something is
const crypto = require('crypto');
const truths = [
'so true',
'undeniably true',
'This response is undeniably true;',
'So true!',
'This is true;',
'true',
'false',
'Untrue'
];
function sentenceHash (sentence) {
const symbols = sentence
.trim()
.toLowerCase()
.split('')
.sort()
.filter(char => 'abcdefghijklmnopqrstuvwxyz123456789'.split('').includes(char))
.join('');
return crypto.createHash('md5').update(symbols + process.env.HOWTRUE_SALT).digest('hex');
}
function howTrue (text) {
return truths[parseInt(sentenceHash(text).substring(0, 5), 16) % truths.length];
}
module.exports = async function (req, res, [ text ]) {
res.header('Hash-Output', sentenceHash(text));
res.send(howTrue(text));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment