Skip to content

Instantly share code, notes, and snippets.

View nathan-lapinski's full-sized avatar
💭
♦️s and 🦀

Nate Lapinski nathan-lapinski

💭
♦️s and 🦀
View GitHub Profile
console.log('is this thing on??');
@nathan-lapinski
nathan-lapinski / Iterator_example.js
Last active May 20, 2018 13:21
An example of a simple iterator.
const megamanBosses = {
[Symbol.iterator]: () => {
return {
next: () => {
const stop = Math.random() > 0.85;
if (!stop) {
return {
value: megaManNameCreator(),
done: false
@nathan-lapinski
nathan-lapinski / pokemon-home.component.ts
Created May 23, 2018 10:12
A simple Angular component
import { Component } from ‘@angular/core’;
@Component({
selector: ‘pokemon-home’,
template: `
<div><h1>{{name}}</h1></div>
`
})
export class PokemonHomeComponent {
name: string = ‘Pokemon, go!’;
const arr = [1,2,3];
const arr = [1,2,3];
const mappedArr = arr.map(value => value + 1); // returns [2,3,4]
@nathan-lapinski
nathan-lapinski / build_your_own_map.js
Last active June 4, 2018 08:50
Simple implementation of array.prototype.map
// overriding properties on Array.prototype is a bad idea. This is given for educational purposes only :D
Array.prototype.map = function(projectionFn) {
let retVal = [];
for (let i = 0; i < this.length; i++) {
retVal.push(projectionFn(this[i]));
}
return retVal;
}
@nathan-lapinski
nathan-lapinski / array_filter.js
Created June 4, 2018 08:54
Filtering arrays.
const arr = [1,2,3];
const filteredArr = arr.filter(v => v % 2 === 0); // [2]
@nathan-lapinski
nathan-lapinski / implement_filter.js
Created June 4, 2018 11:42
Implementing Filter
Array.prototype.filter = function(predicateFn) {
let retVal = [];
for (let i = 0; i < this.length; i++) {
if (predicateFn(this[i]) {
retVal.push(this[i]);
}
}
return retVal;
const arr = [1,2,3,4,5,6];
const composedArr = arr.map(x => x + 1).filter(y => y % 2 === 0); // [2,4,6];
const gameData = [
{
title: 'Mega Man 2',
bosses: [
{
name: 'Bubble Man',
weapon: 'Bubble Beam'
},
{
name: 'Metal Man',