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) { | |
| for (let i = 0; i < arr.length; i++) { | |
| // find the smallest index | |
| let minIndex = i; | |
| for (let j = i + 1; j < arr.length; j++) { | |
| if (arr[minIndex] > arr[j]) { | |
| minIndex = j; | |
| } | |
| } |
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 linearSearch = (value, inputArray) => { | |
| for (let i = 0; i < inputArray.length; ++i) { | |
| if (value === inputArray[i]) { | |
| return i | |
| } | |
| } | |
| return null | |
| } | |
| const Arr = [10, 14, 26, 27, 31, 33, 35, 42, 44] |
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 rawObject = { | |
| a: "hello", | |
| b: "world", | |
| c: { | |
| d: 'ordinary', | |
| e: undefined | |
| }, | |
| f: undefined, | |
| g: null, | |
| } |
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
| /** | |
| * Get the user IP throught the webkitRTCPeerConnection | |
| * @param {Function} onNewIP listener function to expose the IP locally | |
| * @return undefined | |
| */ | |
| const getUserIP = (onNewIP) => { // onNewIp - your listener function for new IPs | |
| //compatibility for firefox and chrome | |
| let myPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection; | |
| let pc = new myPeerConnection({iceServers: [] }), | |
| noop = () => {}, |
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 binarySearch(targetValue, array) { | |
| let min = 0; | |
| let max = array.length - 1; | |
| let count = 0; | |
| let guessedIndex; | |
| while (min <= max) { | |
| count++; | |
| guessedIndex = Math.floor((max + min) / 2); |