@kangax created a new interesting quiz, this time devoted to ES6 (aka ES2015). I found this quiz very interesting and quite hard (made myself 3 mistakes on first pass).
Here we go with the explanations:
(function(x, f = () => x) {
#!/bin/bash | |
# Enhanced version of https://stackoverflow.com/a/52371112/1835055 | |
DIRNAME=${1:-.} | |
cd $DIRNAME | |
FILES=$(mktemp) | |
PACKAGES=$(mktemp) |
const modifier = type => item => Object.prototype.toString.call(item) === `[object ${type}]`; | |
const checkTypes = ['String', 'Function', 'Number', 'Boolean', 'Object', 'Symbol']; | |
const is = checkTypes.reduce((checkers, type) => ({ ...checkers, [type]: modifier(type) }), {}); | |
is.Function(null) |
function bulkRequest(urls) { | |
const promises = urls.reduce((result, url) => { | |
const isValidUrl = Object.prototype.toString.call(url) === '[object String]'; | |
if (isValidUrl) { | |
result.push( | |
fetch(url) | |
.catch(({ message }) => console.warn(`Bulk Request: ${ message }`)) | |
.then(response => ({ [url]: response })) | |
) |
function structuralClone(obj) { | |
return new Promise(resolve => { | |
const {port1, port2} = new MessageChannel(); | |
port2.onmessage = ev => resolve(ev.data); | |
port1.postMessage(obj); | |
}); | |
} | |
var obj = {a: 1, b: { | |
c: b |
@kangax created a new interesting quiz, this time devoted to ES6 (aka ES2015). I found this quiz very interesting and quite hard (made myself 3 mistakes on first pass).
Here we go with the explanations:
(function(x, f = () => x) {
const EXTENSION_TYPE = { | |
0x01: 'PlainText', | |
0xF9: 'GraphicControl', | |
0xFE: 'Comment', | |
0xFF: 'Application' | |
}; | |
/** | |
* Returns total length of data blocks sequence | |
* |
// Find summ of all elements in array => result: 32 | |
var multiArr = [1, '2x', ['3', ['x2', ['10', '10'], '5'], '1x']]; | |
function summ(arr, result) { | |
var result = result || 0; | |
for (var i = 0; i < arr.length; i++) { | |
var number = arr[i]; | |
var notNumber = isNaN(parseInt(number)); | |
var isArray = Object.prototype.toString.call(number) === '[object Array]'; |
function Node(data) { | |
this.data = data; | |
this.next = null; | |
this.prev = null; | |
} | |
function linkedList() { | |
this.head = null; | |
this.size = 0; | |
} |
Here is my recipe how to speed up WebStorm: | |
Go to Preferences and do next: | |
Appearance & Behaviour > System Settings > Updates: disable auto update | |
Appearance & Behaviour > System Settings > Using Statistics: Uncheck allowing sending data | |
Editor > Live Templates: disable all, leave only what you are really use | |
Editor > Emmet: disable all emmets | |
Editor > Intentions: I leave only: CSS, Declaration, JavaScript and Language Injection | |
Plugins: leave only next (* - can be also disabled in case don't need them): | |
CoffeeScript * |
//Iterate through object | |
const obj = { | |
foo: 'bar', | |
comes: 'is', | |
from: 'object' | |
}; | |
for(let key in obj) { | |
if(obj.hasOwnProperty(key)) { | |
let valueOfKey = obj[key]; | |
console.log('%s: %s', key, valueOfKey); |