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 array = [1,[2,[[3], 4],5], [6]]; | |
// the first approach, with two loops | |
function flatFlatten(array) { | |
const flatOne = []; | |
for (let i = 0, j = 0; i < array.length; i++, j = flatOne.length) { | |
const item = array[i]; | |
if (Array.isArray(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
// Ranges covered: | |
// \u0041-\u005a - ABCDEFGHIJKLMNOPQRSTUVWXYZ | |
// \u0061-\u007a - abcdefghijklmnopqrstuvwxyz | |
// \u00c0-\u00d6 - ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ | |
// \u00d8-\u00f6 - ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö | |
// \u00f8-\u00fe - øùúûüýþ | |
// \u0100-\u0131 - ĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬĭĮįİı | |
// \u0134-\u0150 - ĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐő | |
// \u0154-\u017e - ŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽž |
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 totalTime(...times) { | |
let hours = 0; | |
let minutes = 0; | |
for (const time of times) { | |
const [h, m] = time.split(':'); | |
hours += Number(h); | |
minutes += Number(m); | |
} |
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 equation() { | |
let step = 1; | |
let solution = 0; | |
while (true) { | |
const x = solution + step; | |
const tmp = 3 * x ** 3 + 5 * x; | |
switch (true) { | |
case tmp == 16: |
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 shuffle(array) { | |
if (array.length === 0) { | |
return []; | |
} | |
const copy = [...array]; | |
const result = []; | |
const rand = (min, max) => Math.floor(Math.random() * (max - min) + min); | |
do { |
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
setInterval((dto) => { | |
const rand = Math.random(); | |
dto.count++; | |
dto.acc = dto.acc + rand; | |
console.table([{ | |
cnt: dto.count, | |
rnd: rand, | |
acc: dto.acc, |
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
<html> | |
<head> | |
<title><form> parser</title> | |
<script src="./main.js" type=module defer></script> | |
<style> | |
textarea { | |
font-family: monospace; | |
} | |
</style> |
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
// explanation: https://twitter.com/krazov/status/1139937821396000768 | |
{ | |
const cleanPrototype = (prototype) => Object.create( | |
Object.assign( | |
Object.create(null), | |
prototype, | |
) | |
); | |
const cleanObject = cleanPrototype({ |
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
// interface | |
var MyNotSoClass = { | |
[Symbol.hasInstance](instance) { | |
return Boolean(instance.data && instance.next); | |
} | |
}; | |
var objectRight = { | |
data: 'yes', | |
next: 'also, yes', |
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
{ | |
/* | |
Who-when: Krazov 2019 | |
LinkedList object creator. | |
Instead of storing a list in array or other linear container, the data | |
is organized in a chain of linked items: | |
``` | |
LinkedListCell { | |
value: any; | |
next: LinkedListCell | null; |
NewerOlder