<!--
MODULE 9 - PROGRAM 1 - SHELDON PASCIAK
---
//TODO - This is a fully working version, however, I hope to find the time to further abstract/encapsulate - With little input/feedback, I was/am unaware if this is required for full credit, but will make the attempt to reengineer once I have a working submission - the speed of the class dictated this way ahead for my submissions - please advise accordingly
(additional output information in console window)
accepts user input 0..6
interpolates values of rain for hour input
uses numerical indexed lookup table (provided)
-->
Enter the number of hours between 0..6 (including decimals) <br />
Click the button to find the interpolated amount of rain using <br />
<br />
<input type="text" id="userValue" value=4.5 placeholder="Which Hour ? 0.0 ... 6.0 ?" />
<input type="button" id="interpButton" value="Interpolate the Amount of Rain" />
<br/>
<p id="demo"></p>
<!--
Module 9 - Indexes
Introduction
Just like many of the other data structures covered in this class - indexes are also pretty straightforward. They are covered in Topic - Indexing Techniques. For this module you will only have to complete a computer program.
Assignment
An interpolation table is a specific instance of a Lookup Table - which is also a practical application of indexing, in this case numeric indexes. You will create a computer program that uses the following lookup table (interpolation table), allows a user to input a number and calculates the answer by interpolating between 2 numbers - or finds an exact solution.
0 0.00
1 0.04
2 0.11
3 0.60
4 0.87
5 0.95
6 1.00
The table gives the amount of total rainfall (normalized to 1) that occurred during a rainfall event.
For example at hour 3, 0.6 or 60% of the total rain had fallen. You will need to create a function that allows me to enter a number between 0 and 6, and it must return the total amount of rainfall that has occurred. I must also...
JavaScript
// module 9 - program 1 - sheldon paciak
/*
notes: LOOKUP TABLE INFO For ordered lists that must be accessed sequentially, such as linked lists or files with variable-length records lacking an index, the average performance can be improved by giving up at the first element which is greater than the unmatched target value, rather than examining the entire list.
NOTES: LINEAR SEARCH In computer science, linear search or sequential search is a method for finding a particular value in a list that checks each element in sequence until the desired element is found or the list is exhausted.[1] The list need not be ordered.
*/
function calculateSlopes(arr,slps) {
slps[0] = 0;
console.log("i: " + 0 + " --- " + arr[0]);
for (var i=1;i<arr.length;i++) {
console.log("i: " + i + " --- " + arr[i]);
slps[i] = arr[i]-arr[i-1] ; // change in value
}
};
$("#interpButton").click( function() {
var userValue = parseFloat($('#userValue').val());
var valueFloor = Math.floor($('#userValue').val());
if ((userValue<0) || (userValue>lookupTableValues.length-1)) {
alert("I can only interpolate between 0..6!");
return;
}
var valueNext = valueFloor + 1;
var diffValues = parseFloat(userValue - valueFloor);
if (diffValues===0) {
document.getElementById("demo").innerHTML = "Exact match to lookup - Rain for " + valueFloor + " = " + Number(lookupTableValues[valueFloor]).toFixed(2);
} else {
console.log("user value: " + userValue );
console.log( "low: " + valueFloor + " --> " + lookupTableValues[valueFloor] + " slope between next value and previous in table --> " + slopes[valueNext] );
console.log("Next value: " + valueNext + " --> " + lookupTableValues[valueNext] );
console.log( "Difference in values: " + diffValues );
console.log( "Amount of rain: " + Number( lookupTableValues[valueFloor]...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.