Created
May 5, 2014 19:18
-
-
Save thequbit/bc9aa4f7076b6429ab51 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<script> | |
// return our array of dicts | |
function getFaultData() { | |
// create array of dict | |
var retData = [{ | |
"Name": "Fault A", | |
"Status": "FAULT", | |
"FaultBits": [ | |
false, | |
false, | |
true, | |
true, | |
false, | |
false | |
] | |
}]; | |
// return data | |
return retData; | |
} | |
// populate our global | |
var faultData = getFaultData(); | |
// function for processing fault data | |
function processFault(faultIndex) { | |
// pull the data out of the dict of the array at the faultIndex index | |
var name = faultData[faultIndex].Name; | |
var status = faultData[faultIndex].Status; | |
var faultBits = faultData[faultIndex].FaultBits; | |
// make a copy of the faultBits array so we can use splice() | |
faultBitsTemp = faultBits; | |
// get the first half of the faults using splice for the top | |
var faultBitsTop = faultBitsTemp.splice(0,faultBitsTemp.length/2); | |
// since splice is distructive, just set the remainder to the bottom | |
var faultBitsBottom = faultBitsTemp; | |
// display our top and bottom new arrays | |
console.log("faultBitsTop:"); | |
console.log(faultBitsTop); | |
console.log("faultBitsBottom:"); | |
console.log(faultBitsBottom); | |
// display our remaining temp array (should be the second part of the original array) | |
console.log("faultBitsTemp:"); | |
console.log(faultBitsTemp); | |
// display our original ( should be untouched, and length 6 ) | |
console.log("faultData[faultIndex].FaultBits:"); | |
console.log( faultData[faultIndex].FaultBits ); | |
// | |
// ^^^ this is incorect, faultBits has been modified!!! | |
// | |
} | |
// execute | |
processFault( 0 ); | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Dear Tim, this is the answer. On line 36, replace with the following:
dumb.