This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* From https://v1.dinerojs.com/dinero.js | |
* Allocates the amount of a Dinero object according to a list of ratios. | |
* | |
* Sometimes you need to split monetary values but percentages can't cut it without adding or losing pennies. | |
* A good example is invoicing: let's say you need to bill $1,000.03 and you want a 50% downpayment. | |
* If you use {@link module:Dinero~percentage percentage}, you'll get an accurate Dinero object but the amount won't be billable: you can't split a penny. | |
* If you round it, you'll bill a penny extra. | |
* With {@link module:Dinero~allocate allocate}, you can split a monetary amount then distribute the remainder as evenly as possible. | |
* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function flip(arr, right) { | |
let temp; | |
let left = 0; | |
while (left < right) { | |
temp = arr[left]; | |
arr[left] = arr[right]; | |
arr[right] = temp; | |
// scroll |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Success<a> { | |
value: a; | |
} | |
interface Failure<e> { | |
error: e; | |
} | |
type Result<a, e> = Success<a> | Failure<e>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sharp = require('sharp'); | |
const fs = require('fs'); | |
const directory = './public'; | |
const extensions = ['jpeg', 'jpg', 'png', 'webp', 'avif', 'gif', 'svg', 'tiff']; | |
const breakpoints = [640, 768, 1024, 1280, 1536]; | |
fs.readdirSync(directory) | |
.filter(filterImagePath) | |
.forEach((dir) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// stringChallenge va a divide el problema en dos pequeñas soluciones | |
// conocer el valor en 24 horas, para hacer las fácil una comparación de tiempo entre 0 y 24 | |
// convertir las horas en minutos para hacer una diferencia simple | |
function stringChallenge(strArr) { | |
// pair nos va a servir como auxiliar para comparar los elementos en el arreglo | |
// podríamos hacer una doble iteración y seria una solución fácil, pero no optima | |
let pair = []; | |
// min es el valor actual, de la diferencia entre las horas | |
// la estaremos actualizando a medida que hagamos las comparaciones | |
let min = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function largestPair(num) { | |
let pair = null; | |
num | |
.toString() | |
.split("") | |
.forEach((val, index, arr) => { | |
if (arr.length - 1 !== index) { | |
let currentPair = parseInt(val + arr[index + 1]); | |
if (pair < currentPair) pair = currentPair; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function simpleAdding(num) { | |
let sum = 0; | |
for (let i = 0; i <= num; i++) sum += i; | |
return sum; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function capitalize(word) { | |
return word.replace(word[0], word[0].toUpperCase()) | |
} | |
function letterCapitalize(str) { | |
return str.split(" ").map(capitalize).join(" "); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const regex = /\W|_/g; | |
function longest(acc, elem) { | |
if (acc.length < elem.length && !regex.test(elem)) return elem; | |
return acc | |
} | |
function longestWord(sen) { | |
return sen.split(" ").reduce(longest, ""); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* First Reverse | |
* Have the function FirstReverse(str) take the str parameter | |
* being passed and return the string in reversed order. | |
* For example: if the input string is "Hello World and Coders" | |
* then your program should return the string sredoC dna dlroW olleH. | |
* | |
* Test Cases | |
* > firstReverse "Hello World and Coders" | |
* "sredoC dna dlroW olleH" |
NewerOlder