Skip to content

Instantly share code, notes, and snippets.

View sebasluke's full-sized avatar
💭
Yeah, well, that's just, like, your opinion, man

Raúl González sebasluke

💭
Yeah, well, that's just, like, your opinion, man
View GitHub Profile
@sebasluke
sebasluke / pigLatin.js
Last active July 11, 2019 17:53
Pig Latin
function translatePigLatin(str) {
const getFirstVow = str => str.search(/a|e|i|o|u/)
const firstVow = getFirstVow(str)
if(firstVow > 0) return `${str.slice(firstVow)}${str.slice(0, firstVow)}ay`
if(firstVow === 0) return `${str}way`
return str + 'ay';
}
console.log(translatePigLatin("consonant"));
function fearNotLetter(str) {
const letters = "abcdefghijklmnopqrstuvwxyz"
const strArr = str.split("")
const posInAlphabet = char => letters.indexOf(char)
const diffPos = (char1, char2) => posInAlphabet(char2) - posInAlphabet(char1);
const returnLetter = (strArr) => {
if (strArr.length === 1) return undefined;
const [x, ...xy] = strArr
@sebasluke
sebasluke / sortedUnion.js
Created July 14, 2019 23:57
from freecodecamp Write a function that takes two or more arrays and returns a new array of unique values in the order of the original provided arrays. In other words, all values present from all arrays should be included in their original order, but with no duplicates in the final array. The unique numbers should be sorted by their original ord…
function uniteUnique(arr) {
var getArgsArr = (args) => {
var finalList = []
for (var i in args) {
finalList.push(args[i])
}
return finalList.flat()
}
@sebasluke
sebasluke / convertHtmlEntities.js
Created July 15, 2019 00:17
from freecodecamp Convert the characters &, <, >, " (double quote), and ' (apostrophe), in a string to their corresponding HTML entities. Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
function convertHTML(str) {
// &colon;&rpar;
return str.replace(/&/g, "&amp;").
replace(/</g, "&lt;").
replace(/>/g, "&gt;").
replace(/"/g, "&quot;").
replace(/'/g, "&apos;");
}
console.log(convertHTML("Dolce & Gabbana"));
@sebasluke
sebasluke / sumOddFibonacciNums.js
Created July 15, 2019 02:47
From freeCodeCamp Given a positive integer num, return the sum of all odd Fibonacci numbers that are less than or equal to num. The first two numbers in the Fibonacci sequence are 1 and 1. Every additional number in the sequence is the sum of the two previous numbers. The first six numbers of the Fibonacci sequence are 1, 1, 2, 3, 5 and 8. For e…
function sumFibs(num) {
const fibonacci = num => {
if(num === 0) return 1;
if(num === 1) return 1;
return fibonacci(num - 1) + fibonacci(num - 2)
}
const isOdd = num => num % 2 > 0;
@sebasluke
sebasluke / sumAllPrimes.js
Last active July 15, 2019 21:06
From freecodecamp Sum all the prime numbers up to and including the provided number. A prime number is defined as a number greater than one and having only two divisors, one and itself. For example, 2 is a prime number because it's only divisible by one and two. The provided number may not be a prime. Remember to use Read-Search-Ask if you get s…
function sumPrimes(num) {
var isDivisable = (dividend, divisor) => dividend % divisor === 0;
var isPrime = num => {
var treshold = Math.ceil(num / 2);
var isNumberPrime = (num, treshold) => {
if (treshold === 1) return true;
if (isDivisable(num, treshold)) return false
return isNumberPrime(num, treshold - 1)
}
@sebasluke
sebasluke / smallestCommonMultiple.js
Created July 18, 2019 22:19
Find the smallest common multiple of the provided parameters that can be evenly divided by both, as well as by all sequential numbers in the range between these parameters. The range will be an array of two numbers that will not necessarily be in numerical order. For example, if given 1 and 3, find the smallest common multiple of both 1 and 3 th…
function smallestCommons(arr) {
var sortArrays = arr => arr.sort((x, y) => x - y)
var seqBetween = (init, end) => {
return Array(end - init + 1).fill().map((it, i) => init + i)
}
const organizedArr = sortArrays(arr)
const [init, end] = organizedArr
const seqArr = seqBetween(init, end)
@sebasluke
sebasluke / dropElement.js
Created July 19, 2019 20:35
from freecodecamp.org. Given the array arr, iterate through and remove each element starting from the first element (the 0 index) until the function func returns true when the iterated element is passed through it. Then return the rest of the array once the condition is satisfied, otherwise, arr should be returned as an empty array. Remember to …
function dropElements(arr, func) {
// Drop them elements.
var arrTrue = arr.map(func)
var first = arrTrue.indexOf(true)
var last = arrTrue.lastIndexOf(true)
return arr.slice(first, last + 1)
}
@sebasluke
sebasluke / steamRoller.js
Created September 3, 2019 19:41
Steamroller: Flatten a nested array. You must account for varying levels of nesting. Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
function steamrollArray(arr) {
// I'm a steamroller, baby
var arrStr = arr.toString().split(",")
var isStrNaN = (str) => {
if (str === "") return true
return isNaN(Number(str))
}
var isStrObject = (str) => str === "[object Object]"
@sebasluke
sebasluke / gist:27a24ad3b1e5ca0a863f2e0ba542704c
Created September 17, 2019 18:11
Translate to binary from freecodeCamp
var Alphabet = {
"01100001": "a",
"01100010": "b",
"01100011": "c",
"01100100": "d",
"01100101": "e",
"01100110": "f",
"01100111": "g",
"01101000": "h",
"01101001": "i",