Skip to content

Instantly share code, notes, and snippets.

Avatar
👷‍♂️
looking for a job

Rinat Valiullov RinatValiullov

👷‍♂️
looking for a job
View GitHub Profile
View array_iteration_thoughts.md

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

View angle-arrow-down.md

HTML:

  <div class="wrapper">
    <div class="check icon"></div>
  </div>

CSS:

@RinatValiullov
RinatValiullov / Maximum.md
Last active Jun 25, 2017
Getting the maximum number
View Maximum.md
function checkNumbers(a, b, c) {
	if ( a > b ) {
	
		if ( a > c ) {
			console.log("maximum = " + a);
		} else {
			console.log("maximum = " + c);
		}
@RinatValiullov
RinatValiullov / closure.md
Last active Jun 30, 2017
Learn Closure (замыкание)
View closure.md
// Enclosing function (Внешняя (родительская) функция )
function numberGenerator() {
	var num; // локальная "свободная" переменная

	// Внутренняя (дочерняя) функция. Имеет доступ к переменной "num" благодаря замыканию
	function checkNumber(num) {
		num++; // Увеличиваем на единицу входящий параметр
		console.log(num); // Выводим в консоль
	}
View power_function.md
var pow=  function (x, n){
  
  if( n !== 1 ) {
    return (x * pow(x, n-1));
  } else {
    return x;
  }
  
@RinatValiullov
RinatValiullov / what-forces-layout.md
Created Oct 21, 2017 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.
View what-forces-layout.md

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Element

Box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
  • elem.clientLeft, elem.clientTop, elem.clientWidth, elem.clientHeight
  • elem.getClientRects(), elem.getBoundingClientRect()
View Exponent.md
let step = (base, exponent) => {
	exponent = exponent || 2;
	
	/* Ternary operator(other way):
	 * (exponent == undefined) ? exponent = 2 : exponent;
	 */
    
  	let res = 1;
@RinatValiullov
RinatValiullov / convertHEX_to_RGB.js
Last active Nov 21, 2017
Convert Hexidecimal to RGB value(for colors)
View convertHEX_to_RGB.js
let HEX_to_RGB = (hex) => {
let r = hex.substr(0,2),
g = hex.substr(2,2),
b = hex.substr(4,2);
return {
r: parseInt(r, 16),
g: parseInt(g, 16),
b: parseInt(b, 16)
@RinatValiullov
RinatValiullov / addSpaces.js
Last active Nov 21, 2017
Add spaces in string and deleted first blank (with regular expressions)
View addSpaces.js
let addSpaces = (str) => {
str = str.replace(/([A-Z])/g, ' $1');
let removeInitBlank = () => {
return str.replace(/^\s/, '');
}
return removeInitBlank();
};
@RinatValiullov
RinatValiullov / list.js
Last active Nov 26, 2017
Function list(), which return an array from arguments
View list.js
// #1 With spread operator (ES6 syntax). Verbose, but interesting
let list1 = function(...args) {
let array = [];
for(let i = 0, len = args.length; i < len; ++i) {
array.push(args[i]);
};
return array;
};
// #1.1 Amazing arrow functions and spread syntax