Skip to content

Instantly share code, notes, and snippets.

View zdfs's full-sized avatar
😡
THANKS. I HATE IT.

Zachary Forrest y Salazar zdfs

😡
THANKS. I HATE IT.
View GitHub Profile

Keybase proof

I hereby claim:

  • I am zdfs on github.
  • I am zdfs (https://keybase.io/zdfs) on keybase.
  • I have a public key ASC_Z5UpU6BxZk4UOO-zMjUtGXhVmAwpd83z_3XuRyk1qgo

To claim this, I am signing this object:

@zdfs
zdfs / array.duplicate.js
Created May 22, 2013 18:55
Get duplicate values of an Array
// Most of this code is from an answer to a question in
// Rebecca Murphey's JS Assessment project
// https://github.com/rmurphey/js-assessment (thanks, Rebecca!)
Array.prototype.duplicate = function() {
var seen = {}, // Object to keep track of duplicate occurrences
ret = [], // Our return array, with the duplicated values
i, l; // iterator vars
@zdfs
zdfs / array.unique.js
Last active December 17, 2015 15:09
Get unique values of an Array
Array.prototype.unique = function() {
var unique = {}, // Object to keep track of unique occurrences
ret = [], // Our return array, with unique values
i, l; // iterator vars
for (i = 0, l = this.length; i < l; i+=1) {
// if the unique object already has the current array value,
// skip to the next value of the array
@zdfs
zdfs / oddsAndEvens.js
Created May 16, 2013 21:48
Sort array by odds and evens
function oddsAndEvens(a,b) {
return Math.abs(a % 2) - Math.abs(b % 2) || a - b;
}
@zdfs
zdfs / findElementsByClass.js
Last active December 17, 2015 10:29
Polyfill for getElementsByClassName
function findElementsByClass(className) {
var result = [],
elements = document.getElementsByTagName("*"),
classes;
for (var i = 0, ilen = elements.length; i < ilen; i+=1) {
if (elements[i].className !== "") {
classes = elements[i].className.split(" ");
for (j = 0, jlen = classes.length; j < jlen; j+=1) {
if (classes[j] === className) {
@zdfs
zdfs / Fibonacci.js
Last active December 17, 2015 03:39
Find the index of a number in an array of Fibonacci numbers. Return error if number is not a Fibonacci number
// Find the index of a number in an array of Fibonacci numbers.
// Return error if number is not a Fibonacci number.
function fibonacci(num) {
var i,
fib = []; // iterator, array
// first two places in the array are always set
fib[0] = 0;