Skip to content

Instantly share code, notes, and snippets.

<?php
$data = getDataFromDatabase();
echo json_encode($data);
?>
function reducer (state, action) {
switch (action.type) {
case "FETCH_FEED_SUCCESS": {
const { feed } = action;
return { ...state, feed };
}
case "FETCH_FOLLOWERS_SUCCESS": {
const { followers } = action;
return { ...state, followers};
}
// Feed reducer
function feed (state, action) {
switch (action.type) {
case "FETCH_FEED_SUCCESS": {
const { feed } = action;
return feed;
}
default:
return state;
}
function printMatrix (matrix) {
for (let i = 0; i < matrix.length; i++) {
const line = matrix[i];
for (let i = 0; i < line.length; i++) {
const element = line[i];
console.log(element);
}
}
}
function printMatrix (matrix) {
for (var i = 0; i < matrix.length; i++) {
var line = matrix[i];
for (var i = 0; i < line.length; i++) {
var element = line[i];
console.log(element);
}
}
}
// file1.js
var C = 5;
function printConstant () {
console.log('Constant value is ', C);
}
function processArray (array) {
for(var i = 0; i < array.length; i++) {
console.log('Element ', array[i]);
}
console.log('I can use variable i outside the loop ', i);
}
public class Example () {
public void processArray (String[] array) {
for(int i = 0; i < array.length; i++) {
System.out.println(array[i]);
}
System.out.println("I cannot use the variable i here");
}
}
@samfcmc
samfcmc / getPositionObjectES6DefaultValues.js
Created January 27, 2019 17:39
getPosition usage in ES6 with default values
const { x = 0, y = 0 } = getPosition();
console.log('POSITION (x, y) = ', x, y);
@samfcmc
samfcmc / getPositionObjectES6.js
Created January 27, 2019 17:38
getPosition usage in ES6
const { x, y } = getPosition();
console.log('POSITION (x, y) = ', x, y);