Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Milos Ristic ristaa

🎯
Focusing
Block or report user

Report or block ristaa

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ristaa
ristaa / concatenationDuplicates.js
Created Feb 14, 2019
Concatenation of arrays and remove duplicates
View concatenationDuplicates.js
/*
* 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 Feb 14, 2019
Concatenation of arrays
View concatenationSimple.js
/*
* Concatenation of arrays
* @arguments Arrays
*/
concatArrays = (...arrays) => {
var children = [].concat(...arrays);
return children;
}
View reactHooksUsage.js
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 Feb 8, 2019
Prototype design pattern in JS using Object.create
View prototypePattern.js
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 Feb 8, 2019
Module design pattern in JS
View modulePattern.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 Sep 17, 2018
Spread/Rest operator
View spread-rest.js
// 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 Sep 12, 2018
Usage of template literals
View strings.js
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 Sep 12, 2018
Filter Helper
View filter.js
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 Sep 12, 2018
find and findIndex Helpers
View find-and-findIndex.js
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 Sep 12, 2018
Usage of map Helper
View map.js
let arr = [1, 2, 3, 4, 5];
let doubled = arr.map(num => {
return num * 2;
});
console.log(doubled); // [2, 4, 6, 8, 10]
You can’t perform that action at this time.