@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) {| function shiftZeros(arr) { | |
| var len = arr.length-1, | |
| lastidx = len, | |
| ZERO = 0; | |
| for (var i = 0; i <= len; i++) { | |
| if (lastidx <= i) break; | |
| while (arr[lastidx] === ZERO) { | |
| lastidx--; |
| /** | |
| * Shortcut transform function for all supported browsers | |
| * @param {String} transform | |
| * @returns {jQuery} | |
| */ | |
| jQuery.fn.transform = function(transform) { | |
| return this.css({ | |
| '-webkit-transform': transform, /* Chrome, Safari 3.1+ */ | |
| '-moz-transform': transform, /* Firefox 3.5-15 */ | |
| '-ms-transform': transform, /* IE 9 */ |
| const isB = (str) => { | |
| const strArr = str.split(''); | |
| const stack = []; | |
| for (let char of strArr) { | |
| if (char.startsWith('[') || char.startsWith('(')) { | |
| stack.push(char); | |
| } else { | |
| // Первый символ строки не открывающаяся скобка, значит уже не верно |
| console.log(1); | |
| (_ => console.log(2))(); | |
| eval('console.log(3);'); | |
| console.log.call(null, 4); | |
| console.log.apply(null, [5]); | |
| new Function('console.log(6)')(); | |
| Reflect.apply(console.log, null, [7]) | |
| Reflect.construct(function(){console.log(8)}, []); | |
| Function.prototype.apply.call(console.log, null, [9]); | |
| Function.prototype.call.call(console.log, null, 10); |
| const If = (cond) => (truly) => (falsy) => [truly, falsy][!cond + 0]() | |
| const result = If(false)(() => 'true')(() => 'false') |
| enum Event { | |
| enum app: String { | |
| case install = "app install" | |
| case launch = "app launch" | |
| } | |
| enum list: String { | |
| case created = "list created" | |
| case deleted = "list deleted" | |
| case refreshed = "list refreshed" |
| var loading = {}, | |
| loaded = {}, | |
| head = document.getElementsByTagName('head')[0], | |
| runCallbacks = function (path, type) { | |
| var cbs = loading[path], cb, i = 0; | |
| delete loading[path]; | |
| while (cb = cbs[i++]) { | |
| cb[type] && cb[type](); | |
| } | |
| }, |
@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) {| var loading = {}, | |
| loaded = {}, | |
| head = document.getElementsByTagName('head')[0], | |
| runCallbacks = function(path, type) { | |
| var cbs = loading[path], cb, i = 0; | |
| delete loading[path]; | |
| while(cb = cbs[i++]) { | |
| cb[type] && cb[type](); | |
| } | |
| }, |
| /** | |
| * @module input_type_tel | |
| */ | |
| modules.define( | |
| 'input', | |
| ['i-bem__dom', 'jquery'], | |
| function (provide, BEMDOM, jQuery, Input) { | |
| /* borschik:include:../../libs/intl-tel-input/build/js/intlTelInput.js */ |