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 / everyHelper.js
Created Sep 12, 2018
every Helper usage
View everyHelper.js
var applesInBaskets = [32, 33, 16, 40];
var pearsInBaskets = [32, 33, 39, 40];
var bananasInBaskets = [6, 10, 12, 17];
function checkBasket(basket) {
return basket >= 20;
}
// All baskets in array should have more than 20 fruits to return TRUE
console.log(applesInBaskets.every(checkBasket)); // false - one basket with apples has less than 20 apples (16)
@ristaa
ristaa / re-declarations-let-const.js
Created Sep 12, 2018
Update and re-declare of let and const
View re-declarations-let-const.js
// This is OK - updating apples
let apples = "3 apples";
apples = "4 apples";
// This is NOT OK - re-declare pears
let pears = "3 pears";
let pears = "4 pears"; // error: Identifier 'pears' has already been declared
// This is OK - different scopes, same variable name
let bananas = "3 bananas";
@ristaa
ristaa / let.js
Created Sep 12, 2018
Usage of let keyword (block-scoped)
View let.js
let howMany = 4;
if(howMany > 3){
let displayApples = "I have more than 3 apples";
console.log(displayApples); // "I have more than 3 apples"
}
console.log(displayApples); // displayApples is not defined
@ristaa
ristaa / forEach.js
Created Sep 11, 2018
forEach helper ES6
View forEach.js
var colors = ['red', 'yellow', 'purple'];
colors.forEach(function(color) {
console.log(color);
});
@ristaa
ristaa / bind-in-constructor-react.js
Created Aug 14, 2018
Bind in constructor - react
View bind-in-constructor-react.js
class App extends React.Component {
constructor(props) {
super(props);
this.state = { message: "Hello World!" };
this.logMessage = this.logMessage.bind(this);
}
logMessage = () => {
console.log(this.state.message);
}
@ristaa
ristaa / arrow-class-react.js
Created Aug 14, 2018
Arrow function in Class property - react
View arrow-class-react.js
class App extends React.Component {
state = {
message: 'Hello World!'
};
logMessage = () => {
console.log(this.state.message);
}
render() {
@ristaa
ristaa / react-bind-arrow-render.js
Created Aug 14, 2018
Bind this using ES6 arrow function in render - react
View react-bind-arrow-render.js
class App extends React.Component {
constructor(props) {
super(props);
this.state = { message: "Hello World!" };
}
logMessage() {
console.log(this.state.message);
}
@ristaa
ristaa / bind-this-in-render.js
Created Aug 14, 2018
Bind this in render function - react
View bind-this-in-render.js
class App extends React.Component {
constructor(props) {
super(props);
this.state = { message: "Hello World!" };
}
logMessage() {
console.log(this.state.message);
}
@ristaa
ristaa / react-fetch-html.js
Created Aug 9, 2018
React Get HTML from other sites
View react-fetch-html.js
import React, { Component } from "react";
import { render } from "react-dom";
import cheerio from "cheerio";
import renderHTML from "react-render-html";
class App extends Component {
state = {
data: [],
logos: []
};
@ristaa
ristaa / react-fetch-json.js
Created Aug 9, 2018
React simple fetch method with JSON
View react-fetch-json.js
import React, { Component } from "react";
import { render } from "react-dom";
class App extends Component {
state = {
data: []
};
componentDidMount() {
this.getDataFromApi();
You can’t perform that action at this time.