This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function stableMatching { | |
Initialize all m ∈ M and w ∈ W to free | |
while ∃ free man m who still has a woman w to propose to { | |
w = first woman on m’s list to whom m has not yet proposed | |
if w is free | |
(m, w) become engaged | |
else some pair (m', w) already exists | |
if w prefers m to m' | |
m' becomes free | |
(m, w) become engaged |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Calls addToCart method on component: | |
<button v-on:click="addToCart"> | |
// Shorthand | |
<button @click="addToCart"> | |
// Arguments can be passed: | |
<button @click="addToCart(product)"> | |
// To prevent default behaviour eg. page reload |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<a v-bind:href="url">...</a> | |
//Shorthand version | |
<a :href="url">...</a> | |
// True of false will add or remove attribute: | |
<button :disabled="isButtonDisabled"> | |
//If isActive is truthy, the class 'active' will appear: | |
<div :class="{ active: isActive }"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<li v-for="item in items" :key="item.id"> {{ item }}</li> | |
// To access the position in the array: | |
<li v-for="(item, index) in items"> | |
// To iterate through objects: | |
<li v-for="(value, key) in object"> | |
// Using v-for with a component | |
<cart-product v-for="item in products" :product="item" :key="item.id"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Element inserted/removed based on truthiness: | |
<p v-if="inStock">{{ product }}</p> | |
<p v-else-if="onSale">...</p> | |
<p v-else>...</p> | |
//Toggles the display: none CSS property: | |
<p v-show="showProductDetails">...</p> | |
//Two-way data binding: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="app"> | |
<p>I have a {{ product }}</p> | |
<p>{{ product + 's' }}</p> | |
<p>{{ isWorking ? 'YES' : 'NO' }}</p> <p>{{ product.getSalePrice() }}</p> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function outside(x) { | |
function inside(y) { | |
return x + y; | |
} | |
return inside; | |
} | |
fn_inside = outside(3); // Think of it like: give me a function that | |
// adds 3 to whatever you give it | |
result = fn_inside(5); // returns 8 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function addSquares(a, b) { | |
function square(x) { | |
return x * x; | |
} | |
return square(a) + square(b); | |
} | |
a = addSquares(2, 3); // returns 13 | |
b = addSquares(3, 4); // returns 25 | |
c = addSquares(4, 5); // returns 41 |