JavaScript functions and programs
I'm converting some of my old C++ functions and programs to JavaScript in order to learn JS and to be able to use the code here on
the website. Among the entries below are ones I've converted so far.
Some of the links go to pages that use JavaScript for their functionality but don't show the
JS source code on the page. In those cases you can use your browser's View Source to find the location of the .js script file and request it
directly in your browser.
JavaScript programs
| Create and solve Caesar and other
substitution ciphers
|
Interactive web page where you can create and solve substitution cryptograms. |
|
Stock price
volatility, annualized
|
Interactive web page for entering daily price data for a stock and calculating its historical volatility as needed for the
Black-Scholes option valuation formula. The page uses the statistics function described below, plus an additional script for
the volatility and annualization calculations. |
| Black-Scholes
option valuation |
Interactive web page for entering current and strike prices, volatility, dividend, and interest rate data to view and
compare stock option valuation estimates calculated using different variations of the
Black-Scholes method. The script also has functions for some financial calculations such as present and future value, calendar
days between two dates, and two statistical functions related to the standard normal distribution: one calculates the
probability density function z(x), and the other the left or right tail areas under the curve P(x) and Q(x). |
| Website hack attempt identifier and classifier |
The web page is an online calculator where you can enter lines from your website's HTTP access logs and learn whether
any of them were hack attempts. If they were, the calculator classifies them by type. The JavaScript uses regular
expression matches to make the classifications. |
| Extract search engine queries from website access
logs |
Another online calculator: copy and paste lines from your website's HTTP access logs
to get a report of all the search engine queries that brought visitors to each page. This
is another script with examples of regular
expression use. |
| Text editor with RegExp Search and Replace |
Online text editor page for doing in-place Regular Expression Search and Replace,
testing Regular Expression matching, and other functions such as changing text case. One-click
Undo allows easy experimentation. |
| Online calculator generates HTML photo gallery code |
Article about writing HTML code for a website photo gallery, with an online calculator
that uses JavaScript to generate the code automatically with as many rows and columns as
needed. |
JavaScript utility functions
| Statistics
calculator |
A function that takes as input an array of numbers and returns an associative array whose elements contain
descriptive statistics about
the set. Currently supported are Count, Minimum, Maximum, Range, Sum, Arithmetic/Harmonic/Geometric Means,
Median, Mode, and Standard Deviations with N and N-1
weighting. The page also has an online statistical calculator that uses the function. |
| mylib.js function library |
A file for accumulating JavaScript utility functions needed by the C and C++ programs that I'm converting to JS so they
can run on web pages. |
|
Financial calculations library |
Compound interest; U.S. financial market trading days to calendar days converter; Black-Scholes put and call option
valuation routines. The page has interactive compound interest and trading days calculators. |
| Normal curve calculations library |
Calculates Normal Probability Density Function Z(x) for a point x on any normal curve, and areas P(x), Q(x), A(x) under
the Standard Normal Curve. Interactive calculators on the page allow doing the calculations online. |
Miscellaneous or trivial JavaScripts
| Randomly shorten and lengthen strings |
My first JS. It starts with a set of 1-character strings and shortens or lengthens them randomly. It's a demonstration
about why in evolution the more complex forms appear later than the simpler ones: when the starting set consists of only the least complex
forms (the shortest strings), there's nowhere to go but upward in complexity. It's not because more complex forms are better;
it's only because in the beginning the complex ones are not possible to build. |
|