Skip to content

Instantly share code, notes, and snippets.

Avatar

Lorenzo B. flexaddicted

View GitHub Profile
View map_prototype_usage.js
const doubles = [1, 2, 3, 4].myMap(function(number) {
return number * 2;
});
// or using lambda
// const doubles = [1, 2, 3, 4].myMap(number => number * 2);
console.log(doubles);
View map_prototype.js
Array.prototype.myMap = function(fn) {
const elements = [];
for(let i = 0; i < this.length; i++) {
elements.push(fn(this[i]));
}
return elements;
};
View map_original.js
const doubles = [1, 2, 3, 4].map(function(number) {
return number * 2;
});
// or using lambda
// const doubles = [1, 2, 3, 4].map(number => number * 2);
console.log(doubles);
View map_2_hoc.js
function number2String(number) {
return number.toString(10);
}
function number2DoubledNumber(number) {
return number * 2;
}
function myMap(numbers, fn) {
const elements = [];
View map_hoc.js
function number2String(number) {
return number.toString(10);
}
function myMap(numbers, fn) {
const elements = [];
for(let i = 0; i < numbers.length; i++) {
elements.push(fn(numbers[i]));
}
View map_2_function_for_loop.js
function myMap2(numbers) {
const elements = [];
for(let i = 0; i < numbers.length; i++) {
elements.push(numbers[i] * 2);
}
return elements;
}
View map_function_for_loop.js
function myMap(numbers) {
const elements = [];
for(let i = 0; i < numbers.length; i++) {
elements.push(numbers[i].toString(10));
}
return elements;
}
View map_for_loop.js
const numbers = [1, 2, 3, 4];
const elements = [];
for(let i = 0; i < numbers.length; i++) {
elements.push(numbers[i].toString(10));
}
console.log(elements);
View better_code.swift
class ConsumerViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let webViewBox = createWebView(usingModern: true)
// add webView to the view hierachy
webViewBox.load(urlRequest: URLRequest(url: URL(string: "www.google.it")!))
}
View web_view_box.swift
struct WebViewBox {
let view: UIView & URLRequestable
func load(urlRequest: URLRequest) {
view.load(urlRequest: urlRequest)
}
}