Skip to content

Instantly share code, notes, and snippets.

View viiiprock's full-sized avatar
:octocat:
Can I tweet something here?

Son Dang viiiprock

:octocat:
Can I tweet something here?
View GitHub Profile
@viiiprock
viiiprock / selection-sort.js
Last active June 28, 2020 22:25
Algorithms
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;
}
}
@viiiprock
viiiprock / linear-search.js
Last active June 18, 2020 23:08
Algorithms
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]
@viiiprock
viiiprock / objectFilter.js
Created November 9, 2017 04:00
Object filters
const rawObject = {
a: "hello",
b: "world",
c: {
d: 'ordinary',
e: undefined
},
f: undefined,
g: null,
}
@viiiprock
viiiprock / checkIP.js
Created November 8, 2017 05:45
Check user IP address via webkitRTCPeerConnection
/**
* 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 = () => {},
@viiiprock
viiiprock / binary-search.js
Last active June 14, 2020 01:37 — forked from ba0f3/binary-search.js
binary search algorithm
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);