Skip to content

Instantly share code, notes, and snippets.

View wdospinal's full-sized avatar

Wilson Daniel Ospina León wdospinal

View GitHub Profile
/*================
* Types
================*/
type Pizza = {
name: string;
toppings: string[];
};
type PizzaName = "Pepperoni" | "Meat Lovers" | "Veggie Lovers";
type Size = "small" | "medium" | "large";
@wdospinal
wdospinal / dependecies.js
Created December 13, 2023 20:24
Kyle Nguyen
/* eslint-disable */
const ALL_PACKAGES = {
'package-1': ['package-2', 'package-3'],
'package-2': [],
'package-3': [],
'package-4': ['package-3', 'package-6'],
'package-5': ['package-6'],
'package-6': [],
};
@wdospinal
wdospinal / findDuplicate.py
Created March 25, 2020 19:57
find duplicate number in python using
# Python code to find the
# repeated elements in the
# array where every other
# is present once
# Function to find duplicate
def findDuplicate(arr):
# Find the intersection
# point of the slow and fast.
@wdospinal
wdospinal / findDuplicate.py
Created March 25, 2020 19:57
find duplicate number in python using
# Python code to find the
# repeated elements in the
# array where every other
# is present once
# Function to find duplicate
def findDuplicate(arr):
# Find the intersection
# point of the slow and fast.
@wdospinal
wdospinal / palindromeRearranging.js
Created July 12, 2018 21:18
Given a string, find out if its characters can be rearranged to form a palindrome.
const letters = (words, letter) => {
const newWords = words;
newWords[letter] = newWords[letter] ? newWords[letter] + 1 : 1;
return newWords;
};
function palindromeRearranging2(inputArray) {
const words = inputArray.split('').reduce(letters, {});
const values = Object.values(words);
let ban = false;
@wdospinal
wdospinal / arrayChange.js
Created July 12, 2018 20:16
You are given an array of integers. On each move you are allowed to increase exactly one of its element by one. Find the minimal number of moves required to obtain a strictly increasing sequence from the input.
function arrayChange(inputArray) {
console.log(inputArray);
let counter = 0;
let itemOne = inputArray[0];
for (let i = 1; i < inputArray.length; i += 1) {
const itemTwo = inputArray[i];
if (itemOne === itemTwo) {
itemOne = itemTwo + 1;
counter += 1;
} else if (itemTwo > itemOne) {
@wdospinal
wdospinal / areSimilar.js
Created July 12, 2018 19:39
Two arrays are called similar if one can be obtained from another by swapping at most one pair of elements in one of the arrays.
function areSimilar(a, b) {
const valueLen = a.length;
const otherLen = b.length;
const newB = b;
let errors = 0;
let swapFirst = -1;
let swapSecond = -1;
if (valueLen !== otherLen) return false;
for (let i = 0; i < valueLen; i += 1) {
const itemOne = a[i];
@wdospinal
wdospinal / addBorder.js
Created July 10, 2018 00:15
Given a rectangular matrix of characters, add a border of asterisks(*) to it.
function addBorder(picture) {
const width = picture[0].length + 2;
const asterintics = '*'.repeat(width);
return [
asterintics,
...picture.map(line => `*${line}*`),
asterintics,
];
}
module.exports = addBorder;
// compare the arrays item by item and return the concatenated result
function merge(left, right) {
const result = [];
let indexLeft = 0;
let indexRight = 0;
while (indexLeft < left.length && indexRight < right.length) {
if (left[indexLeft] < right[indexRight]) {
result.push(left[indexLeft]);
indexLeft += 1;
@wdospinal
wdospinal / sameLetters.js
Created June 7, 2018 21:50
Write a function that accepts two strings and returns true if they have the same letters
// Write a function that accepts two strings
// and returns true if they have the same letters
//
// e.g. "mono" and "moon", but not "ret" and "tree"
// divide string in letters count letters verify same count each word
function getLetterCount(word) {
const letters = word.split('');