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 findOddEvenNumbers = (toNumber = 50) => [...Array.from({length: toNumber + 1}).keys()] | |
.reduce((acc, cur) => { | |
cur % 2 === 0 ? acc[0].push(cur) : acc[1].push(cur) | |
return acc | |
}, [[], []]) | |
const evenNubers = findOddEvenNumbers(100)[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
const plus = (a = '') => (b = '') => a + b | |
const applyOperation = (fn) => (acc, cur) => acc.map((value, index) => fn(cur[index])(value)) | |
const matrix = (list) => (fn) => list.reduceRight(applyOperation(fn)) | |
const solve = (list) => (fn) => matrix(list)(fn).join('') | |
const str1 = "Testando".split('') | |
const str2 = "String".split('') | |
const str3 = "de".split('') | |
const str4 = "Varios".split('') |
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 plus = (a = 0) => (b = 0) => a + b | |
const times = (a = 0) => (b = 0) => a * b | |
const minus = (a = 0) => (b = 0) => a - b | |
const obelus = (a = 1) => (b = 1) => a / b | |
const applyOperation = (fn) => (acc, cur) => acc.map((value, index) => fn(cur[index])(value)) | |
const matrix = (list) => (fn) => list.reduceRight(applyOperation(fn)) | |
const solve = (list) => (fn) => matrix(list)(fn) |
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 plus = (a = 0) => (b = 0) => a + b | |
const times = (a = 0) => (b = 0) => a * b | |
const minus = (a = 0) => (b = 0) => a - b | |
const obelus = (a = 1) => (b = 1) => a / b | |
const applyVerticalOperation = (fn) => (acc, cur) => acc.map((value, index) => fn(cur[index])(value)) | |
const applyHorizontalOrDiagonalOperation = (fn) => (list) => list.reduce((acc, cur) => fn(acc)(cur)) | |
const solveVerticalMatrix = (list) => (fn) => list.reduce(applyVerticalOperation(fn)) | |
const solveHorizontalMatrix = (list) => (fn) => list.map(applyHorizontalOrDiagonalOperation(fn)) |
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 arrNumbers = (base = 10) => [...Array.from({"length" : base}).keys()] | |
const plus = (acc, cur, index) => acc.concat(index < 2 ? cur : acc[index - 2] + acc[index - 1]) | |
const fib = (base) => arrNumbers(base).reduce(plus, []) | |
console.log(fib(40)) | |
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 ALPHABET = Array.from({"length": 26} , (_ , char) => String.fromCharCode(65 + char)) | |
const getCharIndex = (letter) => ALPHABET.indexOf(letter) | |
const findNextChar = (index) => (changeTo) => { | |
return index >= 13 | |
? ALPHABET[index - changeTo] | |
: ALPHABET[index + changeTo] | |
} | |
const getChar = (char) => (changeTo = 0) => { | |
return getCharIndex(char) >= 0 | |
? findNextChar(getCharIndex(char))(changeTo) |
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 generateListOfNumbers = (toMax = 50) => [...Array(toMax + 1).keys()].slice(1) | |
const isDivisibleBy = (number) => { | |
return { | |
"3" : "fizz", | |
"5" : "buzz", |
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 testCondition = (min, max, x) => { | |
if (x < min) return min | |
if (x > max) return max | |
return x | |
} | |
const clamp = (min, max, x) => | |
testCondition(min, max, x) | |
// Challenged by lubien ;-) |
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 pairwise = (arr, arg) => | |
/* | |
Primeiro laço (reduce) com os numeros recebidos no array | |
Inicio o reduce com um array contendo 2 posições, um número inteiro que vai armazenar as somas dos indices e um | |
objeto que vai armazenar os indices já usados no processo | |
*/ | |
arr.reduce((acc, cur, indexR, arr) => { | |
/* | |
Segundo laço (forEach) para testar o valor recebido do reduce com cada valor do array com a finalizade de | |
satisfazer a condição do desafio |
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 dateDiff = (d1, d2, type = "days") => { | |
const date1 = d1 instanceof Date ? d1 : new Date(`${d1.slice(6)}, ${d1.slice(3, 5)}, ${d1.slice(0, 2)}`) | |
const date2 = d2 instanceof Date ? d2 : new Date(`${d2.slice(6)}, ${d2.slice(3, 5)}, ${d2.slice(0, 2)}`) | |
return { | |
days: () => { |