Want to implement the function of Excel (EFFECT) on JavaScript
I have given the interest rate of (8,89%) and the duration in months of (48)
Excel returns the effective interest rate of 9,29%.
How i can implement the function in Javascript? I tried:
(1+(interestRate/durationMonths))*durationMonths-1
But it returns not the correct value..
Related
I've spent an hour looking for answers and trying different things so I appreciate any help here.
The following code works great for finding someone's part B effective date. However, when someone's birthday is really on the 1st of a month the 'if' function get's used, and I'm no longer able to format and write the date. It's almost like 'partB_eff' is no longer a date object. (I'm a newbie, so I might just be making this part up.)
I'm getting the error "TypeError: partB_eff.toLocaleDateString is not a function at AutoFill_6_Step_Checklist(Code:24:27)"
How can I resolve this?
let birthday = new Date(e.values[2]);
//this is a date entered from a google form
let bdayCopy = new Date(birthday);
//I created this since I'll be using .setMonth(), and I don't want to change the original date of the birhtday
let bday65 = new Date(bdayCopy.setMonth(bdayCopy.getMonth()+780));
//finds the 65th birthday
let partB_eff = new Date(bdayCopy.setDate(01));
//find's the Medicare part B effective date (the 1st of the month someone turns 65)
if(birthday.getDate()==1){
partB_eff = partB_eff.getMonth-1;
//if the person's birthday is really on the 1st of the month, the part b effective date is the 1st of the month prior. partB_eff must be converted
}
partB_eff = partB_eff.toLocaleDateString('en-us',{year:"numeric",month: "short",day:"numeric"});
//format partB_eff so that it looks nice on paper
partB_eff = partB_eff.getMonth-1;
Doesn't do what you think it does. What it does is get the vound function getDate from your date object, and attempt to subtract one from it. In any other language trying to do subtraction on a function would be a type error, but Javascript is Javascript and allows numeric operations on almost any type. A function minus a number in JS is NaN. NaN doesn't have a method called toLocaleString, hence the error.
What's interesting is that you did the same operation correctly above with bdayCopy.setMonth(bdayCopy.getMonth()+780)
Just do the same thing here
bdayCopy = new Date(bdayCopy.setMonth(bdayCopy.getMonth()-1));
Also some important concepts. if in Javascript is not a function. if is a keyword that starts a conditional statement. You can't do any of the things you can do with a function with if. You can't call it or assign it to a variable or pass ot as a function argument. Clearly understanding what a function is is something you need to do to be able to work in JS, or frankly any other language.
Finally if you are doing date math in JS I strongly recommend you use a date library like DateFns or Moment. Javascript native date APIs are possibly the worst designed date API of any language ever.
I have a search feature that should allow a user to sort through a list of courses based on a few factors such as the course language, subject, effort, and whether the course is open for enrollment, opening for enrollment soon, or archived; based on the date property in the course object. I have the other functions working well but the date sort is stumping me.
I'm blaming lack of sleep last night for my inability to wrap my head around this seemingly simple problem.
My addled brain believes that the proper way to begin this is to parse the date and create a filter along the lines of this ...
namespace.filter('dateFilter', function(){
//following is psuedocode
var output[];
if(dateNow > ds.course_open_date) {logic}
if(dateNow > ds.course_open_date + 30 days) {logic}
if(dateNow > ds.course_close_date) {logic}
if(boolean ds.course_self_paced = true) {logic}
return output;
});
I could use a push in the right direction. I need sleep.
I'm trying to minify my javascript code as much as possible.
What I have 14 times is code like this:
o.split('x');
where o is the object name and x is the delimiter.
To cut code size down, I created this function:
function X(o,d){return o.split(d)}
This allows me to call the same split function like this:
X(o,'x');
Each function call saves me about 3 bytes per call. After the changes, I saved about 20 bytes.
Now what I want to do is convert the second parameter into a number that changes into the delimiter inside the function. I'm using up to 5 different delimiters. I'm not sure if this can be done since I want to support internet explorer 7.
Here's my thoughts on how I would modify the function but I'm not sure which is compatible with every browser new and old including Internet explorer 7.
Idea 1:
function X(o,d){var x=[';','.','=',' ','+'];return o.split(x[d])}
Idea 2:
function X(o,d){var x=';.= +';return o.split(x[d])}
Idea 3 (probably doesn't execute but it would allow me to save tons of bytes):
function X(o,d){return o.split(';.= +'[d])}
Idea 4 (same as idea 3):
function X(o,d){return o.split(';.= +'.substr(d,1))}
I'm just trying to condense the function and make it work for everyone.
The basic idea I'm trying to achieve is that I want a catalog of delimiters in my function that I can choose using a number as the second parameter of the function. The first parameter of the same function is the string that is to be split.
How can I properly write my function with the fewest lines of code possible? or do I have to resort to using a single-quoted character as my second parameter?
First of all, I know I've posted something similar to this previously, but i got one response that I couldn't understand and that was it. So, I am trying to make an app script for google sheets to be able to increase the value of the number in a specific cell every weekday. I already know how to set up the time-based trigger for the timing, so all I need is the actual code. I know very minimal about coding, and this is the best I could come up with:
function onEdit(e) {
var range = e.range
var sheet = e.range.getSheet();
sheet.getRange(range.getRow(), 1).setValue(e.(e + 1));
}
When I try to run it, it says:
TypeError: Cannot read property "range" from undefined.(line 2,file"")
Any ideas on how to fix this would be greatly appreciated! But please, please put it in terms that a noob can understand!
The code you have now is on the right track but with a bit of a misunderstanding.
The onEdit trigger IS a trigger, but it is not a timebased one. onEdit is called every time a cell is edited in the spreadsheet. If you are calling this function from a time-based trigger, it will not pass an event object (e) like it would if it were triggered by an edit, which is why you are getting your error.
Instead, modify your time based trigger to call a different function that doesn't depend on an event object.
My understanding is that it is a static cell that you are incrementing (what I mean by this is that it will always be in the same place) so my suggestion is to grab the spreadsheet, grab the appropriate sheet, grab the cell, and edit its contents, similar to what you are already doing but more manual. In code, it would look like this :
function incrementCell(){
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('SheetName');
var value = sheet.getRange('B2');
value.setValue(value.getValue() + 1);
}
Simply substitute your sheets name and your cells A1 Notation location into the code and point your time-drive trigger to this function and it should work for you.
I'm trying to help a friend to figure out if it's possible to implement DSP algorithms in Max/MSP javascript. He was told so in class, and he asked for my help but I can't find any way to process actual samples.
TL;DR
Is it possible to get samples in and return them out in Max/MSP using javascript?
Thanks
No, it's not, as it's made only for processing messages and not signal vectors. Probably you mixed JavaScript with Java — there is a mxj~ object which allows you to use Java 6 (not higher!) for developing signal processing algorithms. Check out the tutorial, which everyone starts to learn how to use Java with: http://pcm.peabody.jhu.edu/~gwright/stdmp/docs/WritingMaxExternalsInJava.pdf
You can write DSP algorithms using Max’s gen~ and codebox, the syntax for which resembles JavaScript or C.
DSP in Max runs at high priority to avoid audio dropouts, which the js object does not, but it is possible to generate code using JavaScript and load that into a gen~ instance. You can find an example of this bundled with Max itself: search for a file called gen~.dynamicexpr.maxpat
They released a node.js API with Max 8. You can now.
Though not using javascript, like delucis said you can now use gen~ to write dsp code.
Here's a distortion gen~ function using tanh for my own project:
tanh_dist(input, amp, offset)
{
pass1 = input + offset;
pass2 = pass1 * amp;
pass3 = tanh(pass2);
return(dcblock(pass3));
}
I also made a sample patch to show you how to use it (in the codebox). Just copy the following text and paste into an empty max patch window:
----------begin_max5_patcher----------
1168.3ocyW8tbiZCD+y3mBF9TROWOHAXG2qsyzGf9Db4FOxfLVWAACH74bYx
8r2U+ALXv13j3zlOPFu+jzt6uc0tZedhky5r8zRG6ey9K1VVOOwxRIRJvx7a
KmTx9vDRoZYNgYooTtvYpFSP2KTxy1rojJdjWCjSDgaY73UEzPgVA3kAybmZ
iWH+hBbk+yyelq8WM6gWkx3ITgRSnCBypD0RcMRYQZst9a+Jx0QJ6kISjel9
F8CRZ94cBWzAmve9rf2EeX9qwE1jjAGbsstIqHknLx4FIfgvRgEHU4rZkBmv
AgnKFrl6K+piUX704m3994xCLaAIkJnEqnbx5DZadQeDhmxoZSwwYpsyZBO1
w9q2ZZJnOMgOPdCvSnkKj4.uy7zh+C3IN86fp6cgH7ovD5OsQv0ryvBttGxV
lGbdV.OHKf5yBANmxSKYwbRxqyOiIL9Ouru3gvp5TK0+J3RwzzpDAKbKgyoI
6HELBWzNXcwPt+qJjaHBHv+5HC5OhHgifM7cWp9WP82qIzNPAOry6WFZLcLw
SLVEOwH+ymc5M1rSzkyNaaTzBimYbMnTDKgtiVTxx3sTgkCIOukXqVaQxGeK
ScPOLsQDiqE41HpftiUueuFojBfZD.uTUnrTm8yqS5jGSVDsfWwTlhVHDYLl
jJFvgzxxbRndyQk4y.lu9.bZ2hbt5lybcgf4lLHYwwZJAhzwIYg+CMpsg6jk
S4LddAsDZMSDFOnANhtg.2xVsIiKJY+PYGpaoCfuwXmCBJ8DkS7Wv8zjFWHt
fEkwkFQm3gTbs5fzo.8yWZ6LpUvI4CrYHSAHlS.VBNYU4ZRgLbYtpiqAEYYI
cgZ1WBciv.myfBNcYQQV9oAKXwaOydWmAfom6rUHkqp3ZzUPlgXUIYWW1VPR
RLWW6d76IP2VhfJX5P.1sATWtaaYXQVRRG+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