Skip to content

Instantly share code, notes, and snippets.

View ebrunosan's full-sized avatar
👉
Coding

Bruno Santos ebrunosan

👉
Coding
View GitHub Profile
@ebrunosan
ebrunosan / IndexedDB101.js
Created May 31, 2018 18:50 — forked from JamesMessinger/IndexedDB101.js
Very Simple IndexedDB Example
// This works on all devices/browsers, and uses IndexedDBShim as a final fallback
var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB || window.shimIndexedDB;
// Open (or create) the database
var open = indexedDB.open("MyDatabase", 1);
// Create the schema
open.onupgradeneeded = function() {
var db = open.result;
var store = db.createObjectStore("MyObjectStore", {keyPath: "id"});
@ebrunosan
ebrunosan / dataBinding.js
Created May 31, 2018 15:12 — forked from emchateau/dataBinding.js
Two-way data binding in pure Javascript
// http://stackoverflow.com/a/16484266/754377
function DataBind(element, data) {
this.data = data;
this.element = element;
element.value = data;
element.addEventListener("change", this, false);
}
DataBind.prototype.handleEvent = function(event) {
//Given an array, "findShortestWordAmongMixedElements" returns the shortest string within the given array.
//
// Notes:
// * If there are ties, it should return the first element to appear in the given array.
// * Expect the given array to have values other than strings.
// * If the given array is empty, it should return an empty string.
// * If the given array contains no strings, it should return an empty string.
function findShortestWordAmongMixedElements(arr) {
ret = '';
arr.forEach(x => {
// Given a string, "countAllCharacters" returns an object where each key is a character in the given string. The value of each key should be how many times each character appeared in the given string.
// Notes:
// * If given an empty string, countAllCharacters should return an empty object.
function countAllCharacters(str) {
var newArr = str.split("");
var newObj = {};
for (var idx in newArr) {
// Given an object and a key, "getElementsGreaterThan10AtProperty" returns an array containing the elements within the array, located at the given key, that are greater than 10.
// Notes:
// * If the array is empty, it should return an empty array.
// * If the array contains no elements greater than 10, it should return an empty array.
// * If the property at the given key is not an array, it should return an empty array.
// * If there is no property at the key, it should return an empty array.
function getElementsGreaterThan10AtProperty(obj, key) {
var newArr = [];