A function has a few parts:
- The declaration:
function ...
- The name:
function foo...
- The arguments:
function foo(arguments go here!)...
- The code to be executed: (inside the { } brackets):
function foo() {
require 'rubygems' | |
require 'twilio-ruby' | |
account_sid = "<<>>" | |
auth_token = "<<>>" | |
client = Twilio::REST::Client.new account_sid, auth_token | |
from = "+<<>>" # Your Twilio number | |
# "Kile" => "+<<>>", | |
# "Cassie" => "+<<>>" |
class Rot13 | |
attr_accessor :text | |
def initialize(text) | |
@text = text | |
end | |
def encrypt | |
@text = @text.tr('a-zA-Z', 'n-za-mN-ZA-M') | |
end |
// See a list of properties for a givin oject (includeing all in prototype chain) | |
for(var prop in obj){ | |
console.log(prop ": " + obj[prop]) | |
} | |
// See only properties in the object (no protochain) | |
for(var prop in obj){ | |
if (obj.hasOwnProperty(prop)){ | |
console.log(prop ": " + obj[prop]) |
// What will this code print? | |
function can_ride(height) { | |
if(height > 6) { | |
console.log("You can ride the ride"); | |
}else if(height !== 5) { | |
console.log("You can't ride"); | |
}else{ | |
console.log("stop"); | |
} |
def bubble_sort(array) | |
loop do | |
swapped = false | |
(array.length-1).times do |i| | |
if array[i] > array[i + 1] | |
array[i], array[i + 1] = array[i + 1], array[i] | |
swapped = true | |
end | |
end |
class Array | |
def quicksort | |
return [] if empty? | |
pivot = delete_at(rand(size)) | |
left, right = partition(&pivot.method(:>)) | |
return *left.quicksort, pivot, *right.quicksort | |
end | |
end |
def fib(n) | |
return n if (0..1).include?(n) | |
fib(n - 1) + fib(n - 2) | |
end |
class BankAccount | |
attr_reader :balance | |
def initialize(balance) | |
@balance = balance | |
end | |
def display_balance | |
@balance | |
end |
Pull-request Checklist | |
====================== | |
A checklist I shamelessly stole from @anhari. | |
Sweep | |
----- | |
[ ] Any unnecessary comments? | |
[ ] Deleted all debugging statements? |