Skip to content

Instantly share code, notes, and snippets.

View trooperandz's full-sized avatar

Matt Holland trooperandz

View GitHub Profile
@trooperandz
trooperandz / array-prototype-foreach.js
Created May 31, 2018 20:28
Custom forEach prototype
// Create our custom forEach function and attach it to the prototype
Array.prototype.customForEach = function(callback) {
const arr = this;
for(let i = 0; i < arr.length; i++) {
callback(arr[i], i, arr);
}
}
// Execute our custom forEach function
@trooperandz
trooperandz / array-prototype-map.js
Last active May 31, 2018 20:47
Custom map prototype
// Create our custom map function and attach it to the prototype
Array.prototype.customMap = function(callback) {
const arr = this;
const newArr = [];
for(let i = 0; i < arr.length; i++) {
const alteredElement = callback(arr[i], i, arr);
newArr.push(alteredElement);
}
@trooperandz
trooperandz / array-prototype-filter.js
Created May 31, 2018 20:43
Custom filter prototype
// Create our custom filter function and attach it to the prototype
Array.prototype.customFilter = function(callback) {
const arr = this;
const newArr = [];
for(let i = 0; i < arr.length; i++) {
if (callback(arr[i], i, arr)) newArr.push(arr[i]);
}
return newArr;
@trooperandz
trooperandz / array-prototype-reduce.js
Created May 31, 2018 20:57
Custom reduce prototype
// Create our custom reduce function and attach it to the prototype
Array.prototype.customReduce = function(callback, initialValue) {
let accumulator = initialValue;
let arr = this;
for(let i = 0; i < arr.length; i++) {
accumulator = (accumulator ? callback(accumulator, arr[i], i, arr) : arr[i]);
}
return accumulator;
@trooperandz
trooperandz / array-prototype-some.js
Created May 31, 2018 21:03
Custom some prototype
// Create our custom some function and attach it to the prototype
Array.prototype.customSome = function(callback) {
const arr = this;
for(let i = 0; i < arr.length; i++) {
if(callback(arr[i], i, arr)) return true;
}
return false;
}
@trooperandz
trooperandz / array-prototype-every.js
Created May 31, 2018 21:05
Custom every prototype
// Create our custom every function and attach it to the prototype
Array.prototype.customEvery = function(callback) {
const arr = this;
for(let i = 0; i < arr.length; i++) {
if (!callback(arr[i], i, arr)) return false;
}
return true;
}
@trooperandz
trooperandz / array-prototype-find.js
Last active July 7, 2018 04:06
Custom find prototype
// Create our custom find function and attach it to the prototype
Array.prototype.customFind = function(callback) {
const arr = this;
for (let i = 0; i < arr.length; i++) {
if (callback(arr[i], i, arr)) return arr[i];
}
return false;
}
@trooperandz
trooperandz / .babelrc
Last active July 26, 2018 05:05
Babel config file
// See http://babeljs.io/docs/en/env/
{
"presets": ["env", "react"]
}
@trooperandz
trooperandz / webpack.config.js
Last active August 4, 2018 20:24
Basic webpack config file for React app from scratch blog post
const path = require('path');
const webpack = require('webpack');
const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
module.exports = {
entry: './src/index.js',
mode: 'development',
module: {
rules: [
{
@trooperandz
trooperandz / .gitignore
Last active August 5, 2018 05:35
.gitignore file for react app from scratch
node_modules
dist