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
| // This guide encompasses the basics of the Dart programming language. | |
| // It is heavily based off of the Dart guides listed below: | |
| // Library Tour: | |
| // https://dart.dev/guides/libraries/library-tour | |
| // Language Tour: | |
| // https://dart.dev/guides/language/language-tour | |
| // To further explore any of the code, just head to the site: |
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 shuffle = (arr) => { | |
| let currentIndex = arr.length; | |
| let tempValue, randomIndex; | |
| while (0 !== currentIndex) { | |
| randomIndex = Math.floor(Math.random() * currentIndex); | |
| currentIndex -= 1; | |
| tempValue = arr[currentIndex]; | |
| arr[currentIndex] = arr[randomIndex]; | |
| arr[randomIndex] = tempValue; |
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
| class Tree { | |
| constructor(value = null, children = []) { | |
| this.value = value; | |
| this.children = children; | |
| } | |
| *printValues() { | |
| yield this.value; | |
| for(let child of this.children) { | |
| yield* child.printValues; |
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 convertToBytes = (str) => { | |
| return new TextEncoder('utf-8').encode(str); | |
| }; | |
| const dataString = 'TT12345,1:49:52 PM,10/15/13'; | |
| // ODQsODQsNDksNTAsNTEsNTIsNTMsNDQsNDksNTgsNTIsNTcsNTgsNTMsNTAsMzIsODAsNzcsNDQsNDksNDgsNDcsNDksNTMsNDcsNDksNTE= | |
| btoa(convertToBytes(dataString)); |
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 convertHexToRGB = (hex) => { | |
| hex = hex[0] === '#' ? hex.substr(1) : hex; | |
| const rgb = parseInt(hex, 16); | |
| return { | |
| Red: (rgb >> 16) & 0xFF, | |
| Green: (rgb >> 8) & 0xFF, | |
| Blue: rgb & 0xFF | |
| }; | |
| }; |
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 isEqual = (value, other) => { | |
| // Tests - same object type, same length, same items | |
| const type = Object.prototype.toString.call(value); | |
| if (type !== Object.prototype.toString.call(other)) { | |
| return false; | |
| } | |
| if (['[object Array]', '[object Object]'].indexOf(type) < 0) { | |
| return false; |
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 ready = () => { | |
| // Example of checking if library is available | |
| if ('jQuery' in window) { | |
| return; | |
| } | |
| // Example of checking if document is loaded | |
| if (document.body) { | |
| // Do code here... |
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 itemIds = [1,2,3,4,5,6]; | |
| // Using reduce | |
| itemIds.reduce((promise, id) => { | |
| return promise.then(_ => api.deleteItem(id)); | |
| }, Promise.resolve()); | |
| // Using Async/Await | |
| itemIds.forEach(async (item) => { | |
| await api.deleteItem(item); |
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 get = (selector, context) => { | |
| // Select the items to manipulate | |
| const GetNodes = function() { | |
| this.nodes = context ? context.querySelectorAll(selector) : document.querySelectorAll(selector); | |
| }; | |
| // Add new class to nodes | |
| GetNodes.prototype.addClass = function(className) { | |
| for (let i = 0, j = this.nodes.length; i < j; i++) { | |
| this.nodes[i].classList.add(className); |
NewerOlder