Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save byron-perez/6226aeed94b5740318e44a6585ce4670 to your computer and use it in GitHub Desktop.
Save byron-perez/6226aeed94b5740318e44a6585ce4670 to your computer and use it in GitHub Desktop.
ejercicios 21/06/2017
<script>
function factorialIter(n){
var a = 1;
var x = parseInt(n);
for(m = x; m > 0; m--)
{
a = a * m;
}
console.log(a);
}
function sumarElemArray(arr)
{
var suma = 0;
for(i = 0; i < arr.length; i++)
{
suma = suma + arr[i];
}
console.log(suma);
}
function productoElemArray(arr)
{
var producto = 1;
for(i = 0; i < arr.length; i++)
{
producto = producto * arr[i];
}
console.log(producto);
}
function findMin(arr)
{
sorted_arr = insertionSort(arr);
console.log(sorted_arr[0]);
}
function insertionSort(arr)
{
cp_arr = arr;
for (var i = 1; i < cp_arr.length; i++)
{
var j = i;
while( (j > 0) && (cp_arr[j - 1] > cp_arr[j]) )
{
var temp = cp_arr[j - 1];
cp_arr[j - 1] = cp_arr[j];
cp_arr[j] = temp;
j = j - 1;
}
}
return cp_arr;
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment