Неожиданные выходы < /li>
Ожидаемые, но не полученные результаты < /li>
Время выполнения, принятое кодом с использованием эпохи MS различия (дата объекта) < /li>
< /ol>
Эта функция полезна в отношении анализа данных, подобных анализу данных, как говорится в ЧАТГПТ, или в любом случае < /p>
: < /p>
Код: Выделить всё
//entering time
enter = new Date().valueOf();
//No need to modify this
function formatMsg(count,obj){
let status=false;
console.log(" In "+count+" times execution of your function, ");
for(a of Object.entries(obj)){
console.log(""+a[0]+" "+a[1]);
status=true;
}
}
function randomCheck(func,values,count=1000)
{
let list=[];
let unknown=[];
let expect=false,expected=[];
for(let i=0;i{
if(j == a) sum++;
});
obj[""+j+" resulted"] = "" + sum + " times";
sum2+=sum;
}
obj[" Total : "]=sum2;
//for values which are not resulted but expected
values.forEach((a)=>{
if(!list.includes(a)){
expect = true;
expected.push(a);
}
});
if(expect){obj[" Values which are expected to occur but didn't occur over "+count]=" executions";
expected.forEach((a)=>{
obj[" "+a]="";
});
}
//for values which are not expected but resulted
if(sum2!=count){
list.forEach((a)=>{
if(!values.includes(a)){
unknown.push(a)
}
});
obj[" Unknown values occured, "]="";
if(!unknown.length==0){
let temp={};
unknown.forEach(a=>{
if(Object.keys(temp).includes(""+a)){
temp[a]+=1;
}else{
temp[a]=1;
}
});
for(let itr of Object.entries(temp)){
obj[""+itr[0]+" resulted"]=" "+itr[1]+" times";
}
}
}
formatMsg(count,obj);
}
// update myfunc with your function code
myfunc=()=>{
return (Math.floor(Math.random()*100 + 1))
}
//update outputs with your array of outputs
let Outputs = [];
for(let i=1;i
Подробнее здесь: [url]https://stackoverflow.com/questions/79681315/ever-need-a-function-to-check-your-random-or-alike-functions-for-output-statisti[/url]