Skip to content

Instantly share code, notes, and snippets.

View bmdoherty's full-sized avatar

Brendan Doherty bmdoherty

View GitHub Profile
const processInput = str => {
return str
.trim()
.split("\t")
.map(Number);
};
const spread = step => {
step = step.slice(0);
let max = step.reduce((a, b) => Math.max(a, b));
const processInput = str => {
return str
.trim()
.split("\t")
.map(Number);
};
const spread = step => {
step = step.slice(0);
let max = step.reduce((a, b) => Math.max(a, b));
<cfscript>
var bodyDot = {};
bodyDot.grant_type = "authorization_code";
writeDump(bodyDot);
var bodyBracket = {};
bodyBracket['grant_type'] = "authorization_code";
writeDump(bodyBracket);
</cfscript>
@bmdoherty
bmdoherty / object_comparision.js
Created July 5, 2017 15:37
object comparison
// object test for equality fails as object need to be pointing to same reference in memory
// primitives like strings and numbers are compared by their value
function greetFailing(person) {
if (person == { name: 'amy' }) {
return 'hey amy'
} else {
return 'hey arnold'
}
}
<cfscript>
lines = [1,2,3,4];
lines.map(function(line){
var greeting = "you";
if(line eq 3){
greeting = "Roahl Dahl";
}
writeOutput( "Happy Birthday to " & greeting & "<br>");
});
@bmdoherty
bmdoherty / brendan_puzzler.cfm
Created September 2, 2016 12:23
brendan_puzzler
<cfscript>
function f(bytes){
var hash = [];
var unit = 0;
var magnitude = '';
var sizes = [
{'unit':'B', size:1},
{'unit':'KB', size:1024},
{'unit':'MB', size:1024*1024},
@bmdoherty
bmdoherty / puzzle,cfm
Created September 2, 2016 12:00
Friday Puzzle
<cfscript>
function smallestWholeNumberGreaterThanZero(prev, item){
if (prev eq 0){
return item;
}
if (item eq 0){
return prev;
}
<cfscript>
tests = [
// sorted
[true,[1,2,3,4,5]]
,[true,[2,4,6,8,10]]
// 1 swap
,[true,[1,2,3,5,4]]
,[true,[5,2,3,4,1]]
,[true,[1,2,3,5,3]]
<cfscript>
tests = [
// sorted
[true,[1,2,3,4,5]]
,[true,[2,4,6,8,10]]
// 1 swap
,[true,[1,2,3,5,4]]
,[true,[5,2,3,4,1]]
,[true,[1,2,3,5,3]]
<cffunction
name="REMatchGroup"
access="public"
returntype="array"
output="false"
hint="Gets the given group of a captured expression.">
<!--- Define arguments. --->
<cfargument
name="Pattern"