Skip to content

Instantly share code, notes, and snippets.

View jsdbroughton's full-sized avatar
🐒
coiled spring

Jonathon Broughton jsdbroughton

🐒
coiled spring
View GitHub Profile
[{ id: 6, name: `A`, children:[
{ id: 7, name:`00`, children: [
{ id: 8, name:`Retail`, children:[
{ id: 1, name: `1`, data:{ uniqueId:99, building:`A`, floor:`00`, zone:`Retail`, mark:`1` } }
] }
] },
{ id: 9, name:`01`, children: [
{ id: 10, name:`Commercial`, children:[
{ id: 2, name: `1`, data:{ uniqueId:22, building:`A`, floor:`01`, zone:`Commercial`, mark:`1` } }
] }
@jsdbroughton
jsdbroughton / flat-array.js
Last active February 16, 2020 20:43
Non-recursive tree pivot by an arbitrary hierarchy
[
{id:1, data: {uniqueId:16, building:`A`, floor:`00`, zone:`Retail`}},
{id:2, data: {uniqueId:32, building:`A`, floor:`01`, zone:`Commercial`}},
{id:3, data: {uniqueId:64, building:`A`, floor:`02`, zone:`Commercial`}},
{id:4, data: {uniqueId:128, building:`A`, floor:`02`, zone:`Commercial`}},
{id:5, data: {uniqueId:256, building:`B`, floor:`03`, zone:`Residential`}}
];

Keybase proof

I hereby claim:

  • I am jsdbroughton on github.
  • I am jsdbroughton (https://keybase.io/jsdbroughton) on keybase.
  • I have a public key ASD9MDNNldvt4eBSV4q3hnncrfpiyp12bKkCxXekFyxrPQo

To claim this, I am signing this object:

@jsdbroughton
jsdbroughton / IfcGuid.js
Last active September 25, 2017 04:50
Translation of the IfcGuid compression algorithm into ES5 Javascript.
// IfcGuid
// ----------------------------------------------------------------------------
// This class is a service class providing methods to generation and conversion
// between compressed and uncompressed string representations of GUIDs
// according to the algorithms used by the Industry Foundation Classes (IFC).
// The algorithm is based on an implementation in c as follows:
// originally proposed by Jim Forester.
// implemented previously by Jeremy Tammik using hex-encoding
// Peter Muigg, June 1998
// Janos Maros, July 2000
@jsdbroughton
jsdbroughton / ILOOKUP.gs
Created September 7, 2017 17:17
Google Sheets Custom Function that takes a list of sheet names and performs a VLOOKUP type search for the range, key and column reference given.
/**
* Returns an array of indirect single cell references from different sheets.
* @param {A2:A} sheets The column containing sheets' names.
* @param {"E1"} ref The range to return from each sheet.
* @param {string} key Value to match
* @param {int} column The column from which to return a value
* @param {int} headers The number of header rows to ignore in the lookup range
* @customfunction
*/
function ILOOKUP(sheets, ref, keys, column, headers) {
@jsdbroughton
jsdbroughton / ROW_SUM.gs
Created September 7, 2017 17:15
Google Sheets Custom Function that returns an sum for all rows in a range or array.
/**
* Returns a sum for each row of a given array.
* @param {range} range The range or array to sum.
* @customfunction
*/
function ROW_SUM(range) {
if (!range.map) {
range = [[range]]; // deal wih single cell ranges.
}
@jsdbroughton
jsdbroughton / INDIRECT_SUM.gs
Last active September 7, 2017 13:38
Google Sheets Custom Function that returns an array of indirect single cell references from different sheets.
/**
* Returns an array of indirect single cell references from different sheets.
* @param {A2:A} sheets The column containing sheets' names or an array of sheet names
* @param {"E1:E50"} range The single column range reference to totalise from each sheet.
* @customfunction
*/
function INDIRECT_SUM(sheets, range) {
var ss = SpreadsheetApp.getActiveSpreadsheet(),
result = [];
@jsdbroughton
jsdbroughton / findDateCellWithinADataRow.gs
Last active September 6, 2017 15:00
This was prepared to help with a question posted on the Google Apps Script G+ forum. https://plus.google.com/110871587349095016187/posts/NTH6kg94QUr
function findDateCellWithinADataRow() {
// Assumes an embedded script.
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
// Pretend this is the way you want to get teh data
// perhaps from the Google Form submission event.
var row = ss.getRange(rowId, 1, 1, ss.getLastColumn());
var rowValues = row.getValues()[0];
if (!Array.prototype.transpose) {
Array.prototype.transpose = function() {
return this.reduce(function(array, next) {
return next.map(function(item, i) {
return (array[i] || []).concat(next[i]);
});
}, []);
}
}
//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com/array/shuffle [rev. #1]
shuffle = function(v){
for(var j, x, i = v.length; i; j = parseInt(Math.random() * i), x = v[--i], v[i] = v[j], v[j] = x);
return v;
};