This file contains 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
// Block Object | |
function Block(previousHash, data) { | |
this.previousHash = previousHash; | |
this.data = data; | |
this.hash = SHA256(JSON.stringify(this)); | |
} | |
// Blockchain Object | |
function Blockchain() { |
This file contains 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
/** | |
* Returns if ISBN-10 is valid | |
* | |
* @param {string} isbn | |
* @returns {boolean} | |
*/ | |
function isbn10IsValid(isbn) { | |
// split isbn into an array | |
let isbnArr = isbn.split(''); |
This file contains 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
/** | |
* Returns if ISBN-13 is valid | |
* | |
* @param {string} isbn | |
* @returns {boolean} | |
*/ | |
function isbn13IsValid(isbn) { | |
// split isbn into an array | |
let isbnArr = isbn.split(''); |
This file contains 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 split(input, char) { | |
let arr = [ ]; | |
let prevIdx = 0; | |
for (let i = 0; i < input.length; i++) { | |
if (input[i] === char) { | |
let item = ''; | |
for (let j = prevIdx; j < i; j++) { | |
item += input[j]; | |
} | |
arr = [ ...arr, item, ]; |
This file contains 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<title></title> | |
<meta name="viewport" content="width=device-width, initial-scale=1" /> | |
<meta name="description" content="" /> | |
<link rel="stylesheet" type="text/css" href="" /> | |
<link rel="icon" href="favicon.png"> | |
</head> |
This file contains 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 request = indexedDb.open(name: string, ?version: number); | |
request.onupgradeneeded = () => { | |
const database = request.result; | |
const store = database.createObjectStore(name: string, ?options: { ?keyPath: string, ?autoIncrement: boolean }); | |
const index = store.createIndex(indexName: string, keyPath: string, ?options: { ?unique: boolean, ?multiEntry: boolean }); | |
store.transaction.oncomplete = () => { | |
const transaction = database.transaction(storeNames: string[] | string, ?mode: enum = 'readonly' | 'readwrite' ); | |
const store = transaction.objectStore(name: string); |