A mockup of an iPhone using only HTML & CSS. A flexbox layout.
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
// Helper function to provide Array's indexOf method to DOM elements | |
function indexOf(arr, target) { | |
return Array.prototype.indexOf.call(arr, target); | |
} | |
// Get the path of the target node from Root A | |
function getPath(root, target) { | |
let current = target; | |
let path = []; | |
while(current !== root) { |
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 traverse(node, current) { | |
if(node.isEqualNode(current)){ | |
return current; | |
} else { | |
let el = null; | |
for(let i = 0; !el && i < current.children.length; i++){ | |
el = traverse(node, current.children[i]); | |
} | |
return el; | |
} |
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 flatten(input) { | |
var out = []; | |
var loop = function(arr) { | |
return arr.map.((val) => { | |
return Array.isArray(val) ? loop(val) : out.push(val); | |
}); | |
}; | |
loop(input); | |
return out; | |
} |
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 debounce(func, immediate, wait) { | |
let timeout; | |
return function() { | |
let context = this, | |
args = arguments; | |
let callNow = immediate && !timeout; | |
clearTimeout(timeout); | |
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(items, value) { | |
let startIndex = 0, | |
stopIndex = items.length - 1, | |
middle = Math.floor((startIndex + stopIndex) / 2); | |
while(value !== items[middle] && startIndex < stopIndex) { | |
if(value < items[middle]) { | |
stopIndex = middle - 1; | |
} else if (value > items[middle]) { | |
startIndex = middle + 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
let arr = ['a', 'b', 'c', 'd', 'e', 'f', 'g']; | |
let idx = [4, 3, 5, 0, 6, 1, 2]; | |
arr = idx.map((idxVal, index) => { | |
return arr[idx.indexOf(index)]; | |
}); |
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 fieldHeaders = ["First Name", "Last Name", "City", "State", "Country", "Phone Number"]; | |
let data = [["Tom", "Stevens", "Seattle", "WA", "USA", "123-123-1234"], ["Mike", "Williams", "Detroit", "MI", "USA", "234-234-2345"], ["Janie", "Jackson", "Vancouver", "BC", "Canada", "987-977-9876"]]; | |
data.unshift(fieldHeaders); | |
function createCSV(data) { | |
let csvContent = "data:text/csv;charset=utf-8,"; | |
data.forEach((dataArray, index) => { | |
let dataStr = dataArray.join(','); | |
csvContent += index < data.length ? dataStr + '\n' : dataStr; | |
}); |