Skip to content

Instantly share code, notes, and snippets.

View Giagnus64's full-sized avatar

Gianfranco Nuschese Giagnus64

View GitHub Profile
const mapStateToProps = (state, props) => {
return {
balance: state.balance
};
};
const mapDispatchToProps = (dispatch, props) => {
return {
withdraw: () => dispatch({type:'WITHDRAW', amount: 10}),
deposit: () => dispatch({type: 'DEPOSIT', amount: 10}),
};
};
@Giagnus64
Giagnus64 / algos.js
Last active November 23, 2019 23:16
const num1 = 10
const arr1 = [1,2,3]
const isit10 = (num) => {
if(num = 10){
return true
} else {
return false;
}
}
@Giagnus64
Giagnus64 / swap.js
Created January 1, 2020 22:23
Swapping function JS
function swap (arr, index1, index2){
let temp = arr[index1];
arr[index1] = arr[index2];
arr[index2] = temp;
}
@Giagnus64
Giagnus64 / bubblesort.js
Created January 1, 2020 23:16
Bubble Sort JS
function bubbleSort(arr){
//start the endIndex at the last index of the array
let endIndex = arr.length - 1;
//run the loop until the endIndex(sorted portion) is the 0 (the full array)
while(endIndex > 0){
// count the number of swaps to short circuit the loop if it is already sorted
let swaps = 0;
//reset the currentIndex to the beginning of the array each time a new element is sorted
let currentIndex = 0;
// loop over the array, comparing each pair of elements until the comparison element reaches the sorted portion of the array
@Giagnus64
Giagnus64 / selectionSort.js
Created January 1, 2020 23:34
SelectionSort
function selectionSort(arr){
let smallestIndex = 0;
let currentIndex = 1;
let beginningIndex = 0;
//loop until the sorted section is the full array
while(beginningIndex < arr.length){
//loop over the array until the currentIndex has reached the last element
while(currentIndex < arr.length){
//keep track of the smallest index by comparing it to the current index
if(arr[smallestIndex] > arr[currentIndex]){
@Giagnus64
Giagnus64 / insertionSort.js
Last active January 7, 2020 02:02
Insertion Sort JS
function insertionSort(arr){
let beginningIndex = 0;
let currentIndex = 1;
//while the start of the unsorted portion doesnt not start at the after the end of the array
while(currentIndex < arr.length){
//while the currentIndex does not reach the end of the sorted section or the array (index of -1)
while(currentIndex > 0){
//get currentValue(value to be sorted)
currentVal = arr[currentIndex];
//if it is lesser than the last value, swap the two values, otherwise, break out of the loop
@Giagnus64
Giagnus64 / sortingAlts.js
Created January 2, 2020 17:06
Alternate Sorting Implementations JS
function swap (arr, index1, index2){
let temp = arr[index1];
arr[index1] = arr[index2];
arr[index2] = temp;
}
function bubbleSortAlt(arr){
let swaps;
for(let i = arr.length; i > 0; i--){
@Giagnus64
Giagnus64 / simple_sorts.rb
Created January 2, 2020 21:28
Ruby Simple Sorts
arr1 = [8,4,6,2,7]
def swap(arr, index1, index2)
temp = arr[index1]
arr[index1] = arr[index2]
arr[index2] = temp
return arr
end
def bubble_sort(arr)
end_index = arr.size - 1
@Giagnus64
Giagnus64 / app.js
Last active January 7, 2020 03:32
Insertion Sort for Testing
function swap (arr, index1, index2){
let temp = arr[index1];
arr[index1] = arr[index2];
arr[index2] = temp;
}
function insertionSort(arr){
let beginningIndex = 0;
let currentIndex = 1;
//while the start of the unsorted portion doesnt not start at the after the end of the array