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
| const mapStateToProps = (state, props) => { | |
| return { | |
| balance: state.balance | |
| }; | |
| }; |
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
| const mapDispatchToProps = (dispatch, props) => { | |
| return { | |
| withdraw: () => dispatch({type:'WITHDRAW', amount: 10}), | |
| deposit: () => dispatch({type: 'DEPOSIT', amount: 10}), | |
| }; | |
| }; |
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
| const num1 = 10 | |
| const arr1 = [1,2,3] | |
| const isit10 = (num) => { | |
| if(num = 10){ | |
| return true | |
| } else { | |
| return false; | |
| } | |
| } |
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 swap (arr, index1, index2){ | |
| let temp = arr[index1]; | |
| arr[index1] = arr[index2]; | |
| arr[index2] = temp; | |
| } |
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 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 |
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 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]){ |
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 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 |
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 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--){ |
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
| 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 |
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 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 |