Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View ristaa's full-sized avatar
:octocat:
Focusing

Milos Ristic ristaa

:octocat:
Focusing
View GitHub Profile
@ristaa
ristaa / concatenationDuplicates.js
Created February 14, 2019 15:49
Concatenation of arrays and remove duplicates
/*
* Concatenation of arrays and remove duplicates from all of them
* @arguments Arrays
*/
concatArrays = (...arrays) => {
var children = [].concat(...arrays);
var returnArray = [...new Set(children)];
return returnArray;
}
@ristaa
ristaa / concatenationSimple.js
Created February 14, 2019 15:48
Concatenation of arrays
/*
* Concatenation of arrays
* @arguments Arrays
*/
concatArrays = (...arrays) => {
var children = [].concat(...arrays);
return children;
}
@ristaa
ristaa / reactHooksUsage.js
Last active February 12, 2019 11:56
React hooks
import React, { useState, useEffect } from "react";
import ReactDOM from "react-dom";
function hexToRgb(hex) {
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result
? {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16)
@ristaa
ristaa / prototypePattern.js
Created February 8, 2019 13:54
Prototype design pattern in JS using Object.create
var personObject = {
name: "John Doe",
ridingBike: function(){
console.log(`I'm riding a bike, weeeeeeee!!!`);
},
walk: function(howMuch){
console.log(`${this.name} was walking ${howMuch}`);
}
};
@ristaa
ristaa / modulePattern.js
Created February 8, 2019 13:44
Module design pattern in JS
var basketballModule = (function(){
var points = 0;
return {
twoPointsMade: function(){
return points = points + 2;
},
threePointsMade: function(){
return points = points + 3;
@ristaa
ristaa / spread-rest.js
Created September 17, 2018 11:53
Spread/Rest operator
// Spread operator
function fruits(apples, bananas, pears){
console.log(apples);
console.log(bananas);
console.log(pears);
}
fruitsNo = [7, 9, 14];
fruits(...fruitsNo);
/*
@ristaa
ristaa / strings.js
Created September 12, 2018 12:57
Usage of template literals
let firstString = `He says: "Ok, let's do that".`; // He says: "Ok, let's do that".
// Variable interpolation
let name = "Joe";
let secondString = `Hi, my name is ${name}.`; // Hi, my name is Joe.
// Expression interpolation
let isMarry = true;
let thirdString = `Please say hello to ${isMarry ? "Marry" : "Mike"}!`; // Please say hello to Marry!
@ristaa
ristaa / filter.js
Created September 12, 2018 12:16
Filter Helper
let baskets = [12, 5, 8, 130, 44];
function moreThanTenApples(element) {
return (element >= 10);
}
let passed = baskets.filter(moreThanTenApples);
console.log("Those baskets have more than 10 apples: " + passed ); // "Those baskets have more than 10 apples: 12, 130, 44"
@ristaa
ristaa / find-and-findIndex.js
Created September 12, 2018 11:49
find and findIndex Helpers
let fruit = ['banana','pear','ananas', 'apple', 'peach'];
let stuffs = ['desk', 'pen', 'wardrobe'];
function findApple(newFruit){
return newFruit==='apple';
}
console.log(fruit.find(findApple)); // "apple"
console.log(stuffs.find(findApple)); // undefined
@ristaa
ristaa / map.js
Created September 12, 2018 11:32
Usage of map Helper
let arr = [1, 2, 3, 4, 5];
let doubled = arr.map(num => {
return num * 2;
});
console.log(doubled); // [2, 4, 6, 8, 10]