Skip to content

Instantly share code, notes, and snippets.

View patrickodacre's full-sized avatar

Patrick O'Dacre patrickodacre

View GitHub Profile
/**
* Create a new array from the differences between two subject arrays.
*
* @param {array} filterArr Values found in this array but not the other will form the new array.
* @param {array} checkArr filterArr is compared to this array.
* @returns {array} Array of values found in filterArr but not checkArr
*/
function getDiffArr(filterArr, checkArr) {
return filterArr.filter(function (value) {
return checkArr.indexOf(value) === -1;
@patrickodacre
patrickodacre / SumAllNumbersInARange.js
Last active July 16, 2016 03:39
Free Code Camp Intermediate Algorithm Challenge 1
console.log("Code Kata - Intermediate - 1 - Sum All Numbers in a Range.");
/**
* My first attempt.
*
* Thoughts on this attempt:
*
* I wasn't satisfied will all the steps
* and temporary variables needed for this attempt.
*
(function myCustomFilterIIFE() {
"use strict";
angular.module('app')
.factory('myCustomFilter', myCustomFilter);
myCustomFilter.$inject = [];
/**
* Setup a custom filter callback.
(function () {
"use strict";
angular.module('app')
.filter('myFilter', myFilter);
myFilter.$inject = [];
/**
* Used directly in the view in place of 'filter'
@patrickodacre
patrickodacre / CaesarsCipher.js
Last active July 12, 2016 03:03
Solution for Free Code Camp's basic algorithm challenge 16
function rot13(str) { // LBH QVQ VG!
var codeArr = str.split(''); // arrays are fun to work with.
var decodes = codeArr.reduce(function (tempArr, currentValue, currentIndex) {
var charCode = str.charCodeAt(currentIndex);
// Pass through any non-alpha characters.
/**
* Clean an array of any duplicate numbers.
*
* @param {array} arr An array of integers
* @returns
*/
function removeDuplicateNumbers(arr) {
var cleanArr = arr.filter(function filterDupeNumbersFn(number, index, array){
return number !== array[index+1];
@patrickodacre
patrickodacre / removeDuplicates.js
Last active July 8, 2016 10:48
Clean any array of duplicate integers, strings, booleans, undefined or nulls - just for fun.
/**
* Clean an array of any duplicate values.
*
* This would be useful to remove duplicate strings or integers.
* It also works for undefined, true, false, null.
* It does not work for NaN or objects.
*
* @param {array} arr An array of any values.
* @returns
/**
* Using Reduce - ES6 / ES2015 Version
*
* The ...destroyThese param is an ES6 rest param;
* in this case, it captures all arguments passed in and puts
* them into an array called destoryThese. It ignores the
* first argument because it is captured in arr.
*
* @param {array} arr The array to be reduced.
* @param {array} ...destoryThese ES6 rest param.
function mutation(arr) {
var first = arr[0].toLowerCase().split(''),
second = arr[1].toLowerCase().split(''),
len = second.length,
idx = 0,
tempArr = [];
while (idx < len) {
@patrickodacre
patrickodacre / code-kata-basics-10.js
Created July 5, 2016 01:03
Code Kata - Basics - 10
function chunkArrayInGroups(arr, size) {
var newArr = [],
len = arr.length,
end = size,
idx = 0;
while (idx < len) {
var group = arr.slice(idx, end);