This file contains 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 toArray = (str) => Array.from (str, (n) => parseInt (n, 10)); | |
const sumStrings = (a,b) => { | |
a = toArray (a).reverse (); | |
b = toArray (b).reverse (); | |
if (a.length < b.length) [a, b] = [b, a]; | |
if (a.length != b.length) b = [...b, ...new Array (a.length - b.length).fill (0)]; | |
const result = []; | |
for (let i = 0; i < a.length; i += 1) { |
This file contains 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
// 1. Using for loop | |
const reverseFor = (str) => { | |
let reversed = ''; | |
for (var i = str.length - 1; i >= 0; i -= 1) { | |
reversed += str[i]; | |
} | |
return reversed; | |
} | |
// 1.1. Using ES6 for..of loop |
This file contains 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
// Check if number is prime | |
const isPrime = (n) => { | |
for (let i = 2; Math.pow (i, 2) <= n; i += 1) { | |
if (n % i === 0) return false; | |
} | |
return true; | |
} | |
// Find GCD (Greatest Common Divisor) | |
const gcd = (a, b) => { |
This file contains 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
$ git checkout --orphan gh-pages | |
$ git reset --hard | |
$ git commit --allow-empty -m "🎉 Initialize gh-pages branch" | |
$ git push origin gh-pages | |
$ git checkout master |
This file contains 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
/** | |
* Use it like <a data-destination="element-id" onclick="smoothScroll(this, this.dataset.destination)" /> | |
*/ | |
function smoothScroll (trigger, destinationId) { | |
var target = document.getElementById(destinationId); | |
function yCurrent () { | |
if (self.pageYOffset) { | |
return self.pageYOffset; |