Skip to content

Instantly share code, notes, and snippets.

View deerawan's full-sized avatar

Budi Irawan deerawan

View GitHub Profile
var students = [
{ name: 'budi', age: 25 },
{ name: 'inul daramanis', age: 27 },
{ name: 'jupe', age: 37 }
];
var result = students.map(student => student.name + ' dengan umur ' + student.age);
var students = [
{ name: 'budi', age: 25 },
{ name: 'inul daramanis', age: 27 },
{ name: 'jupe', age: 37 }
];
var result = students.map(student => student.name);
var scores = [1, 2, 3, 4];
var result = scores.map(score => score * 2);
var scores = [1, 2, 3, 4];
var newScores = [];
for(var i = 0; i < scores.length; i++) {
newScores.push(scores[i] * 2);
}
var scores = [1, 2, 3, 4];
var result = scores.map(function(score) {
return score * 2;
});
function add(x, y) {
return x + y;
}
// addTen is higher order function
function addTen(fn, x) {
return fn(x, 10)
}
let result = addTen(add, 15);

We are testing a simple controller from imaginable MVC framework.

<?php
class UserController extends AbtractController {

    public function show($id)
    {
        $user = $this->db->find('users',$id);
        if (!$user) return $this->render404('User not found');
/**
Code copyright Dustin Diaz and Ross Harmes, Pro JavaScript Design Patterns.
**/
// Constructor.
var Interface = function (name, methods) {
if (arguments.length != 2) {
throw new Error("Interface constructor called with " + arguments.length + "arguments, but expected exactly 2.");
}
this.name = name;
// Generates a URL-friendly "slug" from a provided string.
// For example: "This Is Great!!!" transforms into "this-is-great"
function generateSlug (value) {
// 1) convert to lowercase
// 2) remove dashes and pluses
// 3) replace spaces with dashes
// 4) remove everything but alphanumeric characters and dashes
return value.toLowerCase().replace(/-+/g, '').replace(/\s+/g, '-').replace(/[^a-z0-9-]/g, '');
};
@deerawan
deerawan / 0_reuse_code.js
Created February 2, 2014 07:00
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console