I have a question about how to use the distribution functions within the jstat library. Specifically, I am focused on studentt.
I've tried this:
var alphaLevel = 0.05;
var degreesOfFreedom = 18;
// the answer I want to get is 2.100922
tStat = jStat.studentt(alphaLevel,degreesOfFreedom);
// but all that is returned is an object with
// members _a,_b,_c (_a=alphaLevel, _b=degreesOfFreedom,_c=undefined).
As explained on the jstat github site, there is a difference between static and instance functions. However, it is above my experience with javascript as to how to do this.
Can anyone explain how to properly call the studentt function and get the proper result?
Thank you!
The usage follows this documentation: http://jstat.github.io/distributions.html#jStat.studentt
So in your example you have two options. Either you can get the result immediately:
var tStat = jStat.studentt.pdf(alphaLevel, degreesOfFreedom);
Or you can return an instance that allows you to pass in multiple values of alpha:
var tStat = jStat.studentt(degreesOfFreedom);
var a1 = tStat.pdf(alpha1);
var a2 = tStat.pdf(alpha2);
Related
I am using IBM BPM 8.6
I have an input string as follows:
"\"RECORD_CONTACT\":\"Maram\" , \"DRUG\":\"Panadol\"
In a script on server side, I want to dynamically create a business object like this:
tw.local.recordContact = Maram;
tw.local.drug = Panadol;
How can I dynamically create the business object?
There are a few problems with your request. The first is that you are not creating a business object, you are creating variables. In IBM BPM the variables have to be declared at design time or you will get an error, so invoking attempting to call something like -
tw.local.myVariable = 'Bob';
Will throw an exception if tw.local.myVariable has not been declared. Base on your other question you asked here (link), I'm going to assume you actually have an ANY variable declared called "return" so that
tw.local.return.myVariable = 'Bob'
will work. Given that I based on Sven's answer I think something like the following will work (you will need to validate)
var str = "\"RECORD_CONTACT\":\"Maram\" , \"DRUG\":\"Panadol\"";
var jsonStr = "{" + str.replace(/\\\"/g,'\"') + "}";
var tempValue = JSON.parse(jsonStr);
var keyArray = Object.keys(tempValue);
var valueArray = Object.values(tempValue);
for(var keyCount=0; keyCount<keyArray.length; keyCount++{
var evalString = "tw.local.return."+keyArray[keyCount]+"="+valueArray[keyCount];
eval(evalString);
}
I'll note that doing this is a very bad idea as it would be very brittle code and that using eval() in this manner opens you up to all sorts of possible exploits. It will also fail badly if the value for one of the keys is not a simple type.
-Andrew Paier
One should know what you are going to do with dynamically created Business Objects (BO) to answer you better. Like a very generic way would be - creating JSON object instead of BO.
But if you want to stick with BO then this is only possible when you know all the BO structure (schema) beforehand during design time.
var str = "\"RECORD_CONTACT\":\"Maram\" , \"DRUG\":\"Panadol\"";
vat objArray = str.split("reg ex to split each object string")
foreach (obj in objArray ){
if(obj.indexOf( "RECORD_CONTACT")!=-1)
tw.local.recordContact = new tw.object.RECORD_CONTACT();
//below goes code get value of each attribute of BPM from string
}
else if(obj.indexOf( "DRUG")!=-1){
//similar code to create BO DRUG
}
Don't forget to create BO before using those :)
I am having a problem working out how to chain syncs in Office JS - I think I have to do one sync to read the values then another sync to write them back - must be simple but I can't find a chaining example.
Basically I am trying to code the equivalent of this VBA code which does a read and a write via an array
Application.ScreenUpdating = False
d1 = MicroTimer
Set rng1 = Worksheets("Sheet1").Range("A1:A1000")
Set rng2 = Worksheets("Sheet1").Range("D1:D1000")
var = rng1.Value2
rng2.Value2 = var
d2 = (MicroTimer - d1) * 1000
MsgBox d2
or even simpler
Worksheets("Sheet1").Range("D1:D1000").Value2=Worksheets("Sheet1").Range("A1:A1000").Value2
To copy the values from one range to another, you can use the following code:
Excel.run(function(context) {
var range1 = context.workbook.worksheets.getItem("Sheet1").getRange("A1:A1000").load('values');
return context.sync()
.then(() => {
var range2 = context.workbook.worksheets.getItem("Sheet1").getRange("D1:D1000");
range2.values = range1.values;
return context.sync();
});
});
You can use the Range-Class OfficeJS gives you.
Here is the full doc: https://dev.office.com/reference/add-ins/excel/range (Also have a look at the examples given there)
To copy the Range, you need to create both ranges and copy the .values[][] from the source to the dest.
For how to copy a two-dimensional array (in this case: values[][]), you should use google.
To Determine the time, you can use the Date()-Class Java gives you.
In ExtJS, using an Ext.Array (after using Ext.Array.difference), I get a resulting array and would like to know the best way to check if the array is empty?
I did use theArray.length as one could do in javascript, but I'm wondering if there is a better way/faster to acheive that? (At first I thought that isEmpty would help but it seems to be working on object, not array)
You can easily add this to the Array prototype like this:
Array.prototype.isEmpty = function(){
return !this.length;
};
var a = ['a','b','c','d'];
var b = ['b','d','f','h'];
var c = Ext.Array.difference(a,b);
var d = [];
console.log(c.isEmpty(), d.isEmpty());
Hope it helps :)
Can anyone tell me the use of document.frmReport in JavaScript code?
My application uses this but I don't have any information about this. Besides, it is an HTML DOM object from what I've searched on the internet. A speedy answer would be very helpful. The code is like this:
function fnAddItems(strSource,strTarget)
{
var f = document.frmReport;
var doAdd;
var objSourceCombo = eval("document.frmReport."+strSource);
var objTargetCombo = eval("document.frmReport."+strTarget);
var selSourceLen = objSourceCombo.length;
var selTargetLen = objTargetCombo.length;
var strSourceText;
var strSourceValue;
var arrIDs;
var arrIDs1;
var IsMultipleSelected;
var strFormat;
}
document.frmReport returns undefined for me. Also, there's no official documentation about it, and it's not in the specs.
So my guess is it's something that's added to the document object earlier in your application by someone else, and is being used now.
Look for document.frmReport = something (probably an object)
Do you understand why relying on eval and global variables is a bad practice now?
<script>
var contentSwiperNumber = 'contentSwiper1';
var navSwiper = new Swiper('.swiper-nav',{
scrollContainer: true,
/*Thumbnails Clicks*/
onSlideClick: function(){
<!-- These work fine -->
contentSwiper1.swipeTo( navSwiper.clickedSlideIndex );
contentSwiper2.swipeTo( navSwiper.clickedSlideIndex );
<!-- !!!!Not Working???? contentSwiperNumber.swipeTo ????-->
contentSwiperNumber.swipeTo( navSwiper.clickedSlideIndex );
}
})
</script>
Is there a way to reference a swiper object name using a string passed to a variable?
Please see the code above where I pass the string:
var contentSwiperNumber = 'contentSwiper1';
in an attempt to reference the swiper object var contentSwiper1
Can you please elaborate on what are you trying to do exactly? From what I am seeing over here, You are putting a string value inside contentSwiperNumber and trying to call swipeTo from it. You are treating a string value as an object with a method in it.
I can say that contentSwiper1 as a variable (Not the string value) is an object itself like navSwiper in your code. When you call
contentSwiper1.swipeTo(index)
here contentSwiper1 is a slider object. But when you call
contentSwiperNumber.swipeTo(index)
You are calling the string. Imagine you are doing
'contentSwiper1'.swipeTo(index)
does that work? I do not think so.
So, either save the objects in a session like amplifyjs which will let you do something like this:
var contentSwiper1 = new Slider('.contentSwiper1', options);
amplify.store('contentSwiper1', contentSwiper1);
To retrieve the object you need, you can use:
var contentSwiperNumber = 'contentSwiper1';
var swiperObject = amplify.store(contentSwiperNumber);
swiperObject.swipeTo(index);
Also, you can use window object to save the swipers you create and then write some logic that does a switch case to return the object you need depending on the contentSwiperNumber
I hope this helps.