Skip to content

Instantly share code, notes, and snippets.

@cawel
cawel / javascript-interview-question-8.js
Last active March 14, 2018 13:47
JavaScript Interview Question
var person = {
_name: 'John Doe',
getSecretIdentity: function (){
return this._name;
}
};
var stoleSecretIdentity = person.getSecretIdentity;
console.log(stoleSecretIdentity());
@cawel
cawel / javascript-interview-question-7.js
Created March 13, 2018 20:45
JavaScript Interview Question
var myObject = {
foo: "bar",
func: function() {
var self = this;
console.log("outer func: this.foo = " + this.foo);
console.log("outer func: self.foo = " + self.foo);
(function() {
console.log("inner func: this.foo = " + this.foo);
console.log("inner func: self.foo = " + self.foo);
}());
@cawel
cawel / javascript-interview-question-3.js
Created March 12, 2018 21:29
JavaScript Interview Question
var age = 20
(function () {
console.log("Original age is " + age)
var age = 30
console.log("The new age is " + age)
})()
@cawel
cawel / javascript-interview-question-6.js
Created March 12, 2018 21:22
JavaScript Interview Question
var foo = function(){
// Some code
};
function bar(){
// Some code
};
@cawel
cawel / javascript-interview-question-5.js
Last active March 14, 2018 14:04
JavaScript Interview Question
var a = [0,1,2,3,4,5,6,7,8,9]
a.slice()
a.splice()
a.concat([24])
a.reverse()
@cawel
cawel / javascript-interview-question-4.js
Created March 12, 2018 19:30
javascript-interview-question-4.js
const operations = []
for (var i = 0; i < 5; i++) {
operations.push(() => {
console.log(i)
})
}
for (const operation of operations) {
operation()
@cawel
cawel / javascript-interview-question-1.js
Last active March 12, 2018 17:10
javascript-interview-question-1.js
const multiply = x => y => z => x * y * z
console.log( multiply(2)(3)(4) )
@cawel
cawel / gist:3fa4bb21572d36a72a24
Created November 25, 2015 23:55
blog-quiz-easy-1
#!/usr/bin/env ruby
require 'socket'
client = TCPSocket.open("127.0.0.1", 2222) {|s| s.send("hello", 0) }
@cawel
cawel / gist:0e0455cfed318ae7007e
Created November 25, 2015 23:51
blog-quiz-easy-2
#!/usr/bin/env ruby
require 'open-uri'
open('http://www.imdb.com/title/tt0421054/') do |f|
f.read.match(/User Rating:<\/b>\s*([\d\.]+\/[\d\.]+)<\/b>/)
puts $1
end
@cawel
cawel / gist:e046d6a5163addc99a0d
Created November 25, 2015 23:48
blog-quiz-easy-3
class Array
def my_map
result = []
each do |e|
result << (yield e)
end
result
end
end