Skip to content

Instantly share code, notes, and snippets.

Avatar

Sebastian Herman sebastianherman

View GitHub Profile
@sebastianherman
sebastianherman / sol.js
Created January 10, 2021 15:57
Intermediate Algorithm Scripting: Everything Be True - freeCodeCamp solution
View sol.js
function truthCheck(collection, pre) {
for (let i in collection) {
if (collection[i].hasOwnProperty(pre)) {
if(!collection[i][pre]) {
return false;
}
} else if (!collection[i].hasOwnProperty(pre)) {
return false;
}
}
@sebastianherman
sebastianherman / sol.js
Created January 10, 2021 15:41
Intermediate Algorithm Scripting: Binary Agents - freeCodeCamp solution
View sol.js
function binaryAgent(str) {
return str.split(" ").map(value => {
return String.fromCharCode(parseInt(value, 2));
}).join("");
}
@sebastianherman
sebastianherman / sol.js
Created January 10, 2021 15:21
Intermediate Algorithm Scripting: Sum All Primes - freeCodeCamp solution
View sol.js
function sumPrimes(num) {
let sum = 0;
const isPrime = n => ![...Array(n).keys()].slice(2).map(i => !(n%i)).includes(true) && ![0,1].includes(n)
for (let i=0; i<=num; i++) {
if (isPrime(i)) {
sum += i;
}
@sebastianherman
sebastianherman / sol.js
Created January 10, 2021 14:27
Intermediate Algorithm Scripting: Convert HTML Entities - freeCodeCamp solution
View sol.js
function convertHTML(str) {
let signs = {'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'\"': '&quot;',
'\'': '&apos;'};
let signKeys = Object.keys(signs);
console.log(signKeys);
@sebastianherman
sebastianherman / sol.js
Created January 10, 2021 14:15
Intermediate Algorithm Scripting: Sorted Union - freeCodeCamp solution
View sol.js
function uniteUnique(arr) {
let newArr = [];
for (let i=0; i<arguments.length; i++) {
for (let j=0; j<arguments[i].length; j++) {
if (!newArr.includes(arguments[i][j])) {
newArr.push(arguments[i][j]);
}
}
@sebastianherman
sebastianherman / sol.js
Created January 10, 2021 14:00
Intermediate Algorithm Scripting: Missing letters - freeCodeCamp solution
View sol.js
function fearNotLetter(str) {
let letters = str.split("");
let alph = 'abcdefghijklmnopqrstuvwxyz'.split("");
let range = alph.slice(alph.indexOf(letters[0]), alph.indexOf(letters[0])+letters.length+1);
console.log("Original range: " + range);
for (let i in str) {
@sebastianherman
sebastianherman / sol.js
Created January 9, 2021 14:28
Intermediate Algorithm Scripting: Diff Two Arrays - freeCodeCamp solution
View sol.js
function diffArray(arr1, arr2) {
let newArr1 = arr1.filter(val => {
return arr2.indexOf(val) == -1;
})
let newArr2 = arr2.filter(val => {
return arr1.indexOf(val) == -1;
})
return newArr1.concat(newArr2);
}
@sebastianherman
sebastianherman / sol.js
Last active January 9, 2021 13:11
Functional Programming: Apply Functional Programming to Convert Strings to URL Slugs - freeCodeCamp solution
View sol.js
function urlSlug(title) {
return title.split(/\W/).filter(item => item).map(item => item.toLowerCase()).join("-")
}