Skip to content

Instantly share code, notes, and snippets.

View Sarav-S's full-sized avatar

Sarav Sarav-S

View GitHub Profile
function generate(number) {
return number * 2;
}
generate(2) // returns 4
generate(2) // returns 4
function generate(number) {
return number * Math.random();
}
generate(number) // returns 1.2770887888419167
generate(number) // returns 0.3149105063079531
// Traditional Javascript
function total(tax) {
return function(subtotal) {
return subtotal + ((subtotal \* tax)/100);
}
}
// ES6
const total = tax => subtotal => subtotal + ((subtotal * tax)/100);
function total(tax) {
return function(subtotal) {
return subtotal + ((subtotal * tax)/100);
}
}
const amount = total(18);
const item1 = amount(100); // Returns 118
const item2 = amount(120); // Returns 141.6
function total(tax) {
return function(subtotal) {
return subtotal + ((subtotal * tax)/100);
}
}
function total(subtotal, tax) {
return subtotal + ((subtotal * tax)/100);
}
const item1 = total(100, 18); // Returns 118
const item2 = total(120, 18); // Returns 141.6
const item2 = total(150, 18); // Returns 177
function total(subtotal, tax) {
return subtotal + ((subtotal * tax)/100);
}
<?php
namespace App;
use App\Model;
class Post extends Model
{
}
<?php
namespace App;
use Illuminate\Database\Eloquent\Model as CoreModel;
class Model extends CoreModel
{
/**
* Returns the last record on posts table
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
/**
* Returns the last record on posts table