Skip to content

Instantly share code, notes, and snippets.

View vcpablo's full-sized avatar
👨‍💻

Pablo Veiga vcpablo

👨‍💻
View GitHub Profile
@vcpablo
vcpablo / parse-tree.js
Created July 8, 2021 15:51
Function that parses a flat tree structure with "parentId" and "order" to a strutcured data tree with "children"
const traverse = (arr, parentId) =>
arr.filter(node => node.parentId === parentId)
.reduce((result, current) => [
...result,
{
...current,
children: traverse(arr, current.id)
}
], [])
@vcpablo
vcpablo / js-procedural-to-functional.js
Created May 12, 2021 20:03
JS - from procedural to functional
const developers = [
{
id: 1,
name: 'John Doe',
age: 29,
sex: 'male',
level: 'senior',
earnings: [
{
month: 'February',
@vcpablo
vcpablo / levenshtein_distance_algorithm.js
Last active May 4, 2021 22:13
Levenshtein Distance algorithm
/* eslint-disable */
/**
Based on https://github.com/ka-weihe/fastest-levenshtein
MIT License
Copyright (c) 2020 Kasper Unn Weihe
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
@vcpablo
vcpablo / contacts-tab1.ts
Created March 3, 2019 20:59
Ionic + Akita state management issue
// Required imports
export class ContactsTab1Page implements OnInit {
contacts$: Observable<Contact[]>;
}
// Constructor
// Executed each time the tab is activated
ionViewWillEnter(){
@vcpablo
vcpablo / single_sequences_equal_chars.js
Created February 12, 2019 21:11
Repeat chars single bigger sequences - JavaScript
/**
* Returns the sequences of repeated subsequence chars
* Example 1: 'Niiiiiiiceee' will return ['iiiiiii', 'eee']
* Example 2: 'NiiiiiiiceeeNiccceeeeeeeeeee' will return ['iiiiiii', 'ccc', 'eeeeeeeeeee']
*
* Notice that in 'Example 2', the 'e'char sequence that is returned is the second one, because it's bigger than the first one.
*/
const singleSequencesEqualChars = function(word) {
let counter,
@vcpablo
vcpablo / collatz.js
Created February 12, 2019 21:07
Collatz Conjecture - Javascript
// Standalone Collatz Conjecture function (https://en.wikipedia.org/wiki/Collatz_conjecture)
const collatz = (input) => {
let result = [];
let value = input;
while(value != 1) {
value = (value % 2 === 0) ? value / 2 : value * 3 + 1;
result.push(value)
}