Skip to content

Instantly share code, notes, and snippets.

View joelbarbosa's full-sized avatar
🏠
Working from home

Joel Barbosa joelbarbosa

🏠
Working from home
View GitHub Profile
@joelbarbosa
joelbarbosa / stack
Last active December 4, 2018 22:00
function createStack() {
const array = [];
return {
push(item) {
array.push(item);
},
pop() {
return array.pop();
},
get length() {
import { createQueue } from './queueu';
function createPriorityQueue() {
const lowPriorityQueue = createQueue();
const highPriorityQueue = createQueue();
return {
enqueue(item, isHighPriority = false) {
isHighPriority
? highPriorityQueue.enqueue(item)
@joelbarbosa
joelbarbosa / queue
Last active December 4, 2018 22:00
queue
function createQueue() {
const queue = [];
return {
enqueue(item) {
queue.unshift(item);
},
dequeue() {
return queue.pop();
@joelbarbosa
joelbarbosa / test.js
Created December 4, 2018 21:56
questions
/*
Questions:
* What do you think PFC.props is doing?
- Creating a Object with reference parameters, map your keys;
* What is the concurrency variable good for?
- Its as especifique option where limits the number of Promise created.
* sendOutStatusEmails ignores errors (except for logging them).
Let's say your task was to make sure the whole function fails as soon sending out any
email failed. How would you adjust the code?
- follows the code:
@joelbarbosa
joelbarbosa / bubblesort.js
Created February 28, 2019 03:10
Bubble Sort
function bublesort(arr1) {
const arr = [...arr1];
let swap
do {
swap = false;
for (i=0; i < arr.length-1; i++) {
if (arr[i] > arr[i+1]) {
let tmp = arr[i];
arr[i] = arr[i+1];
arr[i+1] = tmp;
@joelbarbosa
joelbarbosa / chunk.js
Created February 28, 2019 03:52
Creates an array of elements split into groups the length of size.
// chunk
// Creates an array of elements split into groups the length of size.
const chunk = (input, size) => {
return input.reduce((arr, item, idx) => {
if (idx % size === 0) {
return [...arr, [item]];
} else {
return [...arr.slice(0, -1), [...arr.slice(-1)[0], item]];
}
@joelbarbosa
joelbarbosa / react-native.js
Created October 1, 2019 13:48 — forked from lelandrichardson/react-native.js
React Native flow types
declare var __DEV__: boolean;
declare module 'react-native' {
declare type Color = string | number;
declare type Transform =
{ perspective: number } |
{ scale: number } |
{ scaleX: number } |
// Return the total number of matching pairs of socks that John can sell.
// 9
// 10 20 20 10 10 30 50 10 20
// output
// 3
function sockMerchant(n, ar) {
let totalPair=0;
const debounce = (fn, wait, immediate) => {
let timeout;
return () => {
const later = () => {
timeout = null;
if (!immediate) fn.apply(this)
}
const callNow = immediate && !timeout;
clearTimeout(timeout)
timeout = setTimeout(later, wait)