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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="description" content="following https://medium.com/@natelapinski/learning-observables-part-1-arrays-14480816eb61"> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> |
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
import { Injectable } from '@angular/core'; | |
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; | |
import { Observable } from 'rxjs/Observable'; | |
import { environment } from '../../environments/environment'; | |
export interface HttpOptions { | |
headers?: { [key: string]: string }; | |
query?: { [key: string]: string }; | |
} |
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
// ref: https://x-team.com/blog/rxjs-observables/ | |
// imagine that we have a button and whenever the button is clicked, a quasi-random string is generated and displayed | |
const output = document.querySelector('output'); | |
const button = document.querySelector('button'); | |
Rx.Observable | |
.fromEvent(button, 'click') | |
.subscribe(() => { | |
output.textContent = Math.random().toString(36).slice(2); |
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
// ref; https://developer.mozilla.org/en-US/docs/Learn/JavaScript/First_steps/Useful_string_methods | |
var string = 'This is my string'; | |
// Find length | |
string.length; | |
// Retrieve a specific character | |
string[0]; |
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 exampleArray = [[1,2,[3]],4]; | |
const flatten = [] | |
function flatNestedIntegersArray(nestedArray) { | |
nestedArray.forEach(element => { | |
if( Number.isInteger(element) ) { | |
flatten.push(element) | |
} else { | |
flatNestedIntegersArray(element) | |
} |
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 getQueryVariable(variable) { | |
var query = window.location.search.substring(1); | |
var vars = query.split('&'); | |
for (var i = 0; i < vars.length; i++) { | |
var pair = vars[i].split('='); | |
if (decodeURIComponent(pair[0]) == variable) { | |
return decodeURIComponent(pair[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
navigator.getBattery().then((battery) => { | |
console.log(`${battery.level * 100}%`); | |
battery.addEventListener('levelchange', () => { | |
console.log(`${this.level * 100}%`); | |
}); | |
}); |
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
var options = { | |
enableHighAccuracy: true, | |
timeout: 5000, | |
maximumAge: 0 | |
}; | |
function success(pos) { | |
var crd = pos.coords; | |
console.log('Your current position is:'); |
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
// write ES2015 code and import modules from npm | |
// and then press "Execute" to run your program | |
const entityTypes = [ | |
{ category: 'Root', initial: 'oe', icon: '', class: 'card-root' }, | |
{ category: 'Client', initial: 'c', icon: 'fa fa-diamond', class: 'card-client' }, | |
{ category: 'Site', initial: 's', icon: 'fa fa-map-marker', class: 'card-site' }, | |
{ category: 'Device', initial: 'd', icon: 'fa fa-cubes', class: 'card-device' }, | |
{ category: 'Load', initial: 'l', icon: 'fa fa-cube', class: 'card-load' }, | |
{ category: 'Meter', initial: 'm', icon: 'fa fa-tachometer', class: 'card-meter' }, |