Skip to content

Commit

Permalink
Added .decoded property to result of decode()
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-a-thomas committed Oct 29, 2015
1 parent c670003 commit 80597bc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
10 changes: 4 additions & 6 deletions example.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,10 @@
// Try to decode it
var decoded = ldpc.decode(encoded);
console.log("after decoding: " + decoded.toString());

for (var i = 0; i < message.length; i++) {
if (message[i] != decoded[i]) {
console.error("decoding failed");
break;
}
if (decoded.decoded) {
console.log("decoded successfully");
} else {
console.error("failed to decode");
}
}
</script>
Expand Down
5 changes: 5 additions & 0 deletions ldpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ function LDPC(options) {
});
}
var retVal = encoded.slice(0, options.k); // Return the first k symbols
// Determine if the result is completely decoded yet; .decoded will indicate that
retVal.decoded = true;
retVal.forEach(function(value) {
retVal.decoded &= value > 0 || value === 0;
});
retVal.result = encoded; // .result will be the full array of symbols
return retVal;
};
Expand Down

0 comments on commit 80597bc

Please sign in to comment.