Skip to content

Instantly share code, notes, and snippets.

View joaomaia's full-sized avatar

João Maia joaomaia

  • Porto, Portugal
View GitHub Profile
@joaomaia
joaomaia / bcd2number.js
Created October 15, 2012 14:20
Convert number to bcd and vice versa
/*
* bcd2number -> takes a nodejs buffer with a BCD and returns the corresponding number.
* input: nodejs buffer
* output: number
*/
var bcd2number = function(bcd)
{
var n = 0;
var m = 1;
for(var i = 0; i<bcd.length; i+=1) {
@joaomaia
joaomaia / gist:3235910
Created August 2, 2012 09:40
Jazzychad's Array iteration question.
var add1 = function (arr, val, n) {
//Callback function for the reduce method.
var cb = function(remaining, cur, i, arr) {
if(cur === val && remaining > 0) {
arr[i]++;
--remaining;
}
return remaining;
}