Skip to content

Instantly share code, notes, and snippets.

View mdrmtz's full-sized avatar

Daniel Ramos mdrmtz

View GitHub Profile
/**
procedure bubbleSort(A : list of sortable items )
n = length(A)
repeat
swapped = false
for i = 1 to n-1 inclusive do
// if this pair is out of order
if A[i-1] > A[i] then
// swap them and remember something changed
swap( A[i-1], A[i] )
(function () {
function selectionSort(array){
let tmp, min;
/* advance the position through the entire array */
/* (could do i < array.length-1 because single element is also min element) */
for(let i = 0;i < array.length -1; i++){
/* find the min element in the unsorted a[i .. array.length-1] */
/* assume the min is the first element */
min = i;
/* test against elements after i to find the smallest */
/**
i ← 1
while i < length(A)
j ← i
while j > 0 and A[j-1] > A[j]
swap A[j] and A[j-1]
j ← j - 1
end while
i ← i + 1
end while
/*Given a list of N coins, their values (V1, V2, … , VN), and the total sum S. Find the minimum number of coins the sum of which is S (we can use as many coins of one type as we want), or report that it’s not possible to select coins in such a way that
they sum up to S.
Given coins with values 1, 3, and 5. And the sum S is set to be 9.
Given coins with values 1, 3, and 5. And the sum S is set to be 10.
Given coins with values 1, 3, and 5. And the sum S is set to be 11.
Given coins with values 1, 3, and 5. And the sum S is set to be 20.
*/
(function () {
/*Using a Memo to Avoid Repetitious Calculation*/
(function() {
function calcFibonacci(n, memo) {
// If we've got the answer in our memo, no need to recalculate
if (memo[n] !== -1) {
return memo[n];
}
// Otherwise, calculate the answer and store it in memo
/*
Veronica
|
|
____________
| |
Nathan Sally
| |
| __________
/**
* Implement function verify (text) which checks whether brackets within text are correctly nested.
* You need to consider brackets of three kinds: (), [], <>.
*/
(function() {
function verify(value){
var str = '';
value = value.replace(/[^\(\)\[\]\<\>]/g,'');
Complete the markup for put the number in a badge
--------------
| Inbox |42| |
--------------
|Messages |4| |
---------------
<a href="#">Inbox 42</a>
<button class="btn btn-primary" type="button">
@mdrmtz
mdrmtz / WithNamespace
Last active August 29, 2015 14:19 — forked from chochos/wtf.js
Closure
//IIEF don't populate window namespace
(function () {
// Create a name space
var answers = answers || {};
answers = {
meta: function (fn) {
console.log("en meta");
fn();
},
@mdrmtz
mdrmtz / wtf.js
Last active August 29, 2015 14:19 — forked from chochos/wtf.js
function meta(f) {
console.log("en meta");
f();
}
var lista=[meta,meta,meta];
var fun=function() {
console.log("funcion");
}
for(var i=0;i<lista.length;i++) {
var item=lista[i];