Skip to content

Instantly share code, notes, and snippets.

View ronaiza-cardoso's full-sized avatar
🏳️‍🌈

Ronaíza Cardoso ronaiza-cardoso

🏳️‍🌈
View GitHub Profile
function fib(n) {
// edge cases:
if (n === 0 || n === 1)
return n
/**
* we’ll be building the fibonacci series from the bottom up
* so we’ll need to track the previous 2 numbers at each step
**/
let prevPrev = 0 // 0th fibonacci
let prev = 1 // 1st fibonacci
function Memoization () {
 this.memo = {}
}
Memoization.prototype.fib = n => {
// base cases
 if (n === 0 || n === 1) 
 return n
// see if we’ve already calculated this
const fibRecursion = n => {
if (n === 0 | n === 1)
return n
return fibRecursion(n — 1) + fibRecursion(n — 2)
}
@ronaiza-cardoso
ronaiza-cardoso / fib.md
Last active May 24, 2017 11:27
My Fibonacci problems solutions.

The Fibonacci series is a numerical series where each item is the sum of the two previous items. It starts off like this: 0,1,1,2,3,5,8,13,21... Is usually used in white board interview to know if the candidate has some knowledge about algorithm and The notation.

One of the obvios solotion to solve the Fibonacci series problem is to use recursion, but the problem this is to deal with the maximum call stack problem:

Call stack problem.

Any recursive function use a base case and a recursive case, in Fibonacci this works like this:

@ronaiza-cardoso
ronaiza-cardoso / global-var.ts
Created April 12, 2017 18:06
Service to import global vars
import { Injectable } from '@angular/core';
// Declare LoadingService as a provider in app.module.ts
// Inject LoadingService in your class: constructor(private globalUrls: GlobalUrls){}
// Use the this.globalUrls.SERVER_URL to instantiate your variable
@Injectable()
export class GlobalUrls {
SERVER_URL: string = ''
@ronaiza-cardoso
ronaiza-cardoso / data.json
Last active April 11, 2017 17:05
AutoComplete
(index):23 [Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object…][0 … 99]0: ObjectBAIRRO: "ALTINÓPOLIS"CEP: "35053790"CIDADE: "GOVERNADOR VALADARES"CODCID: "3169"ENDERECO: "RUA ABEL COUTO"ESTADO: "MINAS GERAIS"SIGLA: "MG"__proto__: Object1: Object2: Object3: Object4: Object5:
import {Directive, Attribute} from '@angular/core';
import {NgModel} from '@angular/common';
@Directive({
selector: '[mask]',
host: {
'(keyup)': 'onInputChange()'
}
})
export class Mask {
maskPattern: string;
{
"data": "13/04",
"dia": "Qui",
"inicio": "16:24",
"inicio_intervalo": null,
"fim_intervalo": null,
"fim": "20:55",
"jornada": "05:01",
"ocorrencia": null,
"folga": null,
@ronaiza-cardoso
ronaiza-cardoso / loading-service.ts
Last active April 5, 2017 21:14
Service to focus all Loadings of your application
import { Injectable } from '@angular/core';
import { LoadingController, Loading, AlertController } from 'ionic-angular';
// Declare LoadingService as a provider in app.module.ts
// Inject LoadingService in your class: constructor(public Loading: LoadingService){}
// Use the this.Loading.showLoading(), this.Loading.loadingDismiss() or this.Loading.showError() methods wherever you want
@Injectable()
export class LoadingService {
loading: Loading;