Skip to content

Instantly share code, notes, and snippets.

View Phongtlam's full-sized avatar
🎯
Focusing

phong lam Phongtlam

🎯
Focusing
View GitHub Profile
const adjustPaddings = isScrollDown => {
const container = document.querySelector(".cat-list");
const currentPaddingTop = getNumFromStyle(container.style.paddingTop);
const currentPaddingBottom = getNumFromStyle(container.style.paddingBottom);
const remPaddingsVal = 170 * (listSize / 2);
if (isScrollDown) {
container.style.paddingTop = currentPaddingTop + remPaddingsVal + "px";
container.style.paddingBottom = currentPaddingBottom === 0 ? "0px" : currentPaddingBottom - remPaddingsVal + "px";
} else {
container.style.paddingBottom = currentPaddingBottom + remPaddingsVal + "px";
const recycleDOM = firstIndex => {
for (let i = 0; i < listSize; i++) {
const tile = document.querySelector("#cat-tile-" + i);
tile.firstElementChild.innerText = DB[i + firstIndex].title;
tile.lastChild.setAttribute("src", DB[i + firstIndex].imgSrc);
}
}
const initIntersectionObserver = () => {
const options = {
/* root: document.querySelector(".cat-list") */
}
const callback = entries => {
entries.forEach(entry => {
if (entry.target.id === 'cat-tile-0') {
topSentCallback(entry);
} else if (entry.target.id === `cat-tile-${listSize - 1}`) {
/* jshint esversion: 6 */
// Solve the following prompts using recursion.
// 1. Calculate the factorial of a number. The factorial of a non-negative integer n,
// denoted by n!, is the product of all positive integers less than or equal to n.
// Example: 5! = 5 x 4 x 3 x 2 x 1 = 120
// factorial(5); // 120
var factorial = function(n) {
if (n < 0) return null;
// ['w','h','a','t',' ','o','n',' ','e','a','r','t','h',' ','a','r','e',' ','y','o','u',' ','t','a','l','k','i','n','g',' ','a','b','o','u','t','?']
function isVowel(x) {
var result;
result = x === "a" || x === "e" || x === "i" || x === "o" || x === "u";
return result;
}
function doubleV(array) {
var CashAmount = function(val) {
val = val.toFixed(2)
this.value = val;
}
CashAmount.prototype.totalInPennies = function() {
var array = this.value.split('.');
var first = array[0] + '00';
return parseInt(first) + parseInt(array[1]);
}
var path = require('path');
module.exports = {
entry: path.resolve(__dirname, 'src') + '/app/index.js',
output: {
path: path.resolve(__dirname, 'dist') + '/app',
filename: 'bundle.js',
publicPath: '/app/'
},
var path = require('path');
module.exports = {
entry: path.resolve(__dirname, 'src') + '/app/index.js',
output: {
path: path.resolve(__dirname, 'dist') + '/app',
filename: 'bundle.js',
publicPath: '/app/'
},
@Phongtlam
Phongtlam / gist:6e06e1ba6935dfac0a64ec82fdf4c40b
Created April 6, 2017 16:46
Brute Force - Iterative way to solve Pascal (passed all tests)
/**
* @param {number} numRows
* @return {number[][]}
*/
var generate = function(numRows) {
if (numRows === 0) {
return [];
}
if (numRows === 1) {
return [[1]];
@Phongtlam
Phongtlam / gist:829eb91fbba4939916575e5dc345e5a9
Created April 6, 2017 16:44
Pascal Solution (iterative)
/**
* @param {number} numRows
* @return {number[][]}
*/
var generate = function(numRows) {
var result = [];
result[0] = [1];
result[1] = [1,1];
for (var row = 2; row < n; row++){
result[row] = [1];