Skip to content

Instantly share code, notes, and snippets.

View enricopolanski's full-sized avatar

Enrico Polanski enricopolanski

View GitHub Profile
function InitPlan() {
// gets the date of monday of the current week
this.startingWeek = function() {
let now = new Date();
now.setDate(now.getDate() - now.getDay() + 1);
return (now.getDate() + "-" + (now.getMonth() + 1) + "-" + now.getFullYear());
}();
let timer = 1500;
let startTimer = function(){
if (timer !== 0){
timer -= 1;
timerToTime();
} else{
timer = 1500;
window.clearTimeout(timeoutID);
let delta = 0;
window.setInterval(()=>{
delta++;
first.style.position = delta + "px";
}, 10);
function elementTransition(element, distX){
document.styleSheets[0].insertRule(".transitioning{ transition: transform 100ms linear;"+
"transform: translate(" + distX + "px, 0px);}");
element.classList.add("transitioning");
window.setTimeout((element)=>{
if (distX<0){
element.appendBefore(element.previousElementSibling);
element.previousElementSibling.removeEventListener("mousemove", passedFunction);
}
}, 100);
function clearAll(el, func){
console.log("b");
el.appendBefore(el.previousElementSibling);
el.classList.remove("transitioning");
el.nextElementSibling.style.position = "static";
el.nextElementSibling.removeEventListener("mousemove", func);
}
function elementTransition(element, distX, func){
@enricopolanski
enricopolanski / array_iteration_thoughts.md
Created February 19, 2018 22:58 — forked from ljharb/array_iteration_thoughts.md
Array iteration methods summarized

While attempting to explain JavaScript's reduce method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

Intro

JavaScript Arrays have lots of built in methods on their prototype. Some of them mutate - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. (I'll also insist on referring to an array as a "list" - although in some languages, List is a native data type, in JS and this post, I'm referring to the concept. Everywhere I use the word "list" you can assume I'm talking about a JS Array) This means, to perform a single operation on the list as a whole ("atomically"), and to return a new list - thus making it much simpler to think about both the old list and the new one, what they contain, and

userPlan = {
// plenty of stuff
startingWeek = Date object; // such as Mon Feb 19 2018 16:34:08 GMT+0100 (W. Europe Stand…
// other stuff
}
function saveData(data){
console.log(this) // => correctly logs the userPlan object, including startingWeek property
console.log(this.data) // logs 'undefined'
localStorage.setItem(data, JSON.stringify(this.data)); // => saves: 'startingWeek' : undefined;
window.onclick = (event) => {
if (event.target.classList.contains('modal')) {
event.target.style.display = 'none';
}
};
/* [eslint] Assignment to property of function parameter 'event'. (no-param-reassign)
should this warning be ignored? */
<div class="studiesBoxInner">
<div class="checkBoxContainer">
<input type="checkbox" id="coding" name="interest" value="coding">
<label for="coding">Learn the C Programming Language till pointers</label>
</div>
</div>
<div class="studiesBoxInner">
<div class="checkBoxContainer">
<input type="checkbox" id="algos" name="interest" value="coding">
<label for="algos">Study Algos and Data Structures</label>
'use strict';
function Init() {
// Get current week's Monday.
this.startingWeek = (function startingWeek() {
const date = new Date();
// If it's Sunday, start from the Sunday before