Skip to content

Instantly share code, notes, and snippets.

View victorkurauchi's full-sized avatar
🎯
Focusing

Victor Kurauchi victorkurauchi

🎯
Focusing
View GitHub Profile
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let distinct = 0;
let sorted = A.sort((a, b) => a - b);
let last;
// console.log(sorted)
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let zeroCount = 0;
let combinations = 0;
A.forEach((n, index) => {
if (n === 0) {
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let max = A.length;
let total = (max * (max + 1) / 2);
let partial = 0;
@victorkurauchi
victorkurauchi / smallestpositive.js
Created March 24, 2020 21:30
Returns the smallest positive integer (greater than 0) that does not occur in A
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let sorted = A.filter(a => a >= 1).sort((a, b) => a - b);
// console.log('sorted', sorted)
let minor = 1;
@victorkurauchi
victorkurauchi / observables.js
Last active March 4, 2020 09:45
Rxjs reducing to make serially http calls
// https://stackblitz.com/edit/rxjs-map-pipe-study-b2qoje
import { of, from } from 'rxjs';
import { map, flatMap, catchError } from 'rxjs/operators';
console.clear();
function fakeApiCall(value) {
console.log('Calling', value)
var lookupValues = { "a": 123, "b": 234, "c": 345, "d": 456 };
throw new Error('Hmmmm we are breaking things!')
@victorkurauchi
victorkurauchi / clojure.test.js
Created December 16, 2019 01:48
Testing clojures
const secret = (msg) => () => msg;
// partialApply(targetFunction: Function, ...fixedArgs: Any[]) =>
// functionWithFewerParams(...remainingArgs: Any[])
const partialApply = (fn, ...fixedArgs) => {
return function (...remainingArgs) {
return fn.apply(this, fixedArgs.concat(remainingArgs));
};
};
@victorkurauchi
victorkurauchi / webpack.config.js
Created January 4, 2019 05:36
webpack config with client and server
const path = require('path');
const webpack = require('webpack');
const mode = process.env.NODE_ENV === 'dev' || process.env.NODE_ENV === 'test' ? 'development' : 'production';
const serverConfig = {
target: 'node',
mode: mode,
entry: __dirname + '/src/index.js',
devtool: 'inline-source-map',
resolve: {
@victorkurauchi
victorkurauchi / weather.html
Created January 4, 2019 05:34
weather.html
<html>
<head>
<script src="./weather.min.js"></script>
</head>
<body>
<button onclick="showWeather()">Click to know the weather :)</button>
<script>
function showWeather() {
var weather = new Weather();
[
{
"id": 1,
"name": "sydney",
"price": 700
},
{
"id": 2,
"name": "london",
"price": 600
@victorkurauchi
victorkurauchi / server.js
Last active December 31, 2018 03:15
Fastify server.js consuming weather library
// Require the framework and instantiate it
const fastify = require('fastify')()
const destinations = require('./destinations.json');
// our weather library
const Weather = require('weather');
// Declare a route
fastify.get('/destinations', async (request, reply) => {
reply