Skip to content

Instantly share code, notes, and snippets.

View jeanjmichel's full-sized avatar

Jean Jorge Michel jeanjmichel

View GitHub Profile
@jeanjmichel
jeanjmichel / javascript_2_dimensional_array_manipulator.js
Last active May 17, 2024 17:45
Manipulating two-dimensional arrays in JavaScript
var matrix = {
create: function(rows, columns) {
var newMatrix = [];
for (var i = 0; i < rows; i++) {
var row = [];
for (var j = 0; j < columns; j++) {
row.push(0); // Inicializa a matriz com valores zero
}
newMatrix.push(row);
}
console.debug(`Criando um obj contaCorrente para iniciar o teste`)
const contaCorrente = {
numero: 123456,
cliente: 321,
saldo: 5000
};
const verificarTransacao = (tipoTransacao, contaCorrente, valorTransacao) => {
console.info(`verificarTransacao: Tipo de Transação = ${tipoTransacao} Conta Número = ${contaCorrente.numero} Cliente = ${contaCorrente.cliente} Saldo = ${contaCorrente.saldo} Valor Transação = ${valorTransacao}`)
let liberada
@jeanjmichel
jeanjmichel / MontyHallProblem.js
Last active October 29, 2020 17:49
A JavaScript code to test the Monty Hall Problem.
var myBet = Math.floor(Math.random() * 3) + 1;
var acceptChangeInitialBet = Math.floor(Math.random() * 2) + 1;
function game(initialBet, changeInitialBet) {
var portsAndPrizes = [];
var carPort = Math.floor(Math.random() * 3) + 1;
var newBet;
var discardedDoor;
var finalGoatDoor;
var finalBet;
@jeanjmichel
jeanjmichel / config.yml
Created January 22, 2020 20:25
Exemplo de descritor de build para o Circle CI construir uma aplicação TypeScript
version: 2.1
references:
default_container_config: &default_container_config
docker:
- image: circleci/node:10
working_directory: ~/repo
commands:
install_and_cache_dependencies:
description: "Checkout, get cache, install and save cache"
steps:
@jeanjmichel
jeanjmichel / currying.ts
Created November 12, 2019 21:06
Currying em JavaScript é uma forma de fazer uma função receber parâmetros (que não necessariamente são todos os essenciais para a imediata execução da função) e retornar uma outra função.
const saudarPessoa = (saudacaoNoIdiomaX) => (nomePessoa) => console.log(`${saudacaoNoIdiomaX} ${nomePessoa}`);
const saudarEmIngles = saudarPessoa('Good morning');
const saudarEmEspanhol = saudarPessoa('Buen día');
const saudarEmAlemao = saudarPessoa('Guten Morgen');
saudarEmIngles('John');
saudarEmEspanhol('Juan');
saudarEmAlemao('Jean');
//É o mesmo que
@jeanjmichel
jeanjmichel / factory.pattern.ts
Created November 1, 2019 22:24
Of course this is just an example. And the goal here is to show how you can create a factory of objects (even if each object has an unique relevant set of information).
/**
* In this folder (creational.patterns/factory.pattern/) you will find an
* example implementation of the Factory design pattern. This means that
* you will see that things were created without using the word 'new'.
*
* @author Jean J. Michel
*/
class iPhoneFamily {
public version: string;
public suportedIOs: number;