Skip to content

Instantly share code, notes, and snippets.

View CraigRodrigues's full-sized avatar

Craig Rodrigues CraigRodrigues

View GitHub Profile
@CraigRodrigues
CraigRodrigues / reduce.js
Created November 20, 2016 20:06
Simple reduce function
// array to reduce
// combine is a function that will do something to the current value and the current element
// current is either the start provided or 0 if nothing is provided?
function reduce(array, combine, start) {
var current = start || 0;
for (var i = 0; i < array.length; i++)
current = combine(current, array[i]);
return current;
}
@CraigRodrigues
CraigRodrigues / toyProblems.js
Last active December 23, 2020 03:34
Toy Problems #1
/**
* Given a single input string, write a function that produces all possible anagrams
* of a string and outputs them as an array. At first, don't worry about
* repeated strings. What time complexity is your solution?
*
* Extra credit: Deduplicate your return array without using uniq().
*/
/**
* example usage:
@CraigRodrigues
CraigRodrigues / bubbleSort.js
Last active September 14, 2024 10:41
Bubble Sort in Javascript
// Normal
const bubbleSort = function(array) {
let swaps;
do {
swaps = false;
for (let i = 0; i < array.length - 1; i++) {
if (array[i] > array[i + 1]) {
let temp = array[i + 1];
array[i + 1] = array[i];
array[i] = temp;
// Copyright 2013 Soundslice LLC. License: BSD.
/* HTML example: ****************
<figure class="vid">
<video preload>
<source src="/videos/help/playhead.mp4" type="video/mp4">
<source src="/videos/help/playhead.webm" type="video/webm">
</video>
<p>To move the playhead, click in the timeline or drag the playhead’s diamond.</p>
// Copyright 2013 Soundslice LLC. License: BSD.
/* HTML example: ****************
<figure class="vid">
<video preload>
<source src="/videos/help/playhead.mp4" type="video/mp4">
<source src="/videos/help/playhead.webm" type="video/webm">
</video>
<p>To move the playhead, click in the timeline or drag the playhead’s diamond.</p>
@CraigRodrigues
CraigRodrigues / practiceSpec.js
Last active October 15, 2019 08:28
Function Practice Assertions
// Setup
mocha.setup('bdd');
chai.should();
chai.config.includeStack = false;
const assert = chai.assert;
describe('addTwoNumbers', () => {
it('Adds two positive numbers', function() {
assert.equal(addTwoNumbers(10, 2), 12);
@CraigRodrigues
CraigRodrigues / mindtickle.js
Last active February 27, 2022 17:53
Mindtickle Completion
const SHEET_NAME = 'COMPLETION REPORT';
function getAverage(colName) {
const sheet = SpreadsheetApp.getActiveSheet();
const data = sheet.getDataRange().getValues();
const col = data[0].indexOf(colName);
if (col != -1) {
const completions = sheet.getRange(2,col+1,sheet.getMaxRows()).getValues().map(x => x[0]).filter(x => x !== '');
const completionTotal = completions.reduce((a, b) => a + b);