Skip to content

Instantly share code, notes, and snippets.

@isurfer21
Last active April 18, 2023 11:25
Show Gist options
  • Save isurfer21/562ddada64e44f356cabca4753151f23 to your computer and use it in GitHub Desktop.
Save isurfer21/562ddada64e44f356cabca4753151f23 to your computer and use it in GitHub Desktop.
It is a legacy game of FLAME, that children and teenagers use to play on their crushes. The theory of flame states that it could forecast the relationship in between 2 person by doing a flame-test on their individual names.
/*
The Legacy Game of FLAME
Copyright (c) 2015 Nistush Tech Solution.
Protected by Creative Commons license (CC BY 4.0).
@file flame.js
@author Abhishek Kumar
*/
export function flame(argv) {
if (argv.h || argv.help) {
return `
It is a legacy game of FLAME, that children and teenagers use to play on their crushes.
The theory of flame states that it could forecast the relationship in between 2 person by doing a flame-test on their individual names.
Syntax:
flame [name1] [name2]
where,
[name1] 1st person name
[name2] 2nd person name
Options:
-h --help show help options
-v --ver show version
`;
} else if (argv.v || argv.ver) {
return `FLAME (Version 1.0.0)`;
} else if (argv._.length == 0) {
return `Missing both person names`;
} else if (argv._.length == 1) {
return `Missing another person name`;
} else {
var flame = new FlameTester();
return flame.calculate(argv._.slice(0, 2));
}
}
function FlameTester() {
var FLAME = [
'Friend',
'Lovers',
'Affection',
'Marriage',
'Enemies'
];
var getStatistic = function (list) {
var statistic = [];
for (var i=0; i<list.length; i++) {
statistic[i] = {};
var name = list[i].toLowerCase().split('');
for (var j=0; j<name.length; j++) {
if (statistic[i].hasOwnProperty(name[j])) {
statistic[i][name[j]]++;
} else {
statistic[i][name[j]] = 1;
}
}
}
return statistic;
};
var filterCommons = function (statistic) {
var frequency = {};
for (var i=0; i<statistic.length; i++) {
for (var j in statistic[i]) {
if (i == 0) {
frequency[j] = statistic[i][j];
} else {
if (frequency.hasOwnProperty(j)) {
frequency[j] = null;
} else {
frequency[j] = statistic[i][j];
}
}
}
}
for (var k in frequency) {
if (frequency[k] == null || k == ' ') {
delete frequency[k];
}
}
return frequency;
};
var sigmaFrequency = function (frequency) {
var sum = 0;
for (var k in frequency) {
sum += frequency[k];
}
return sum;
};
var getCode = function (sigma) {
var code = sigma % 5;
return ((code == 0) ? 5 : code);
};
this.calculate = function (inames){
var stats = getStatistic(inames);
var freq = filterCommons(stats);
var sigma = sigmaFrequency(freq);
var code = getCode(sigma);
return FLAME[code - 1];
}
}
@isurfer21
Copy link
Author

isurfer21 commented Feb 8, 2020

Production
Click to Install in WebShell
CDN supported CDN URL

Development
Click to Install in WebShell
CDN supported CDN URL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment