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
/* | |
There is a table in database. This table contains unduplicated natural numbers. There may be gaps in the sequence of natural numbers in the table. You need to output missing numbers. | |
Table of natural numbers: declare @values as table ([number] int not null). | |
Test data: insert into @values([number]) values (1), (2), (3), (5), (9). | |
Result: declare @missing as table ([left] int not null, [right] int not null). | |
*/ | |
DECLARE @values AS TABLE ([number] INT NOT NULL); | |
INSERT INTO @values([number]) VALUES (1), (2), (3), (5), (9); | |
DECLARE @missing AS TABLE ([left] INT NOT NULL, [right] INT NOT NULL) |
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 numberToOrdinal(n) { | |
const | |
number = Math.abs(n) || 0, | |
units = number % 10, | |
tens = ~~(number % 100 / 10), | |
suffix = new Map([ | |
[1, 'st'], | |
[2, 'nd'], | |
[3, 'rd'] | |
]); |
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
/* | |
Twin Strings | |
Two strings, a and b, are said to be twins only if they can be made equivalent by performing some number of operations on one or both strings. There are two possible operations: | |
SwapEven: Swap a character at an even-numbered index with a character at another even-numbered index. | |
SwapOdd: Swap a character at an odd-numbered index with a character at another odd-numbered index. | |
For example, a = "abcd" and b = "cdab" are twins because we can make them equivalent by performing operations. Alternatively, a = "abcd" and b = "bcda" are not twins (operations do not move characters between odd and even indices), and neither are a = "abc" and b = "ab" (no amount of operations will insert a 'c' into string b). | |
Complete the twins function in the provided code. It has two parameters: |
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
Backup = { | |
shell: WScript.CreateObject("WScript.Shell"), | |
base: "C:/BACKUP/", | |
username: "USERNAME", | |
hostname: "HOST", | |
password: "PASSWORD", | |
type: { | |
postgreSQL: function(){ | |
var shell = Backup.shell; | |
var path = "c:/program files/postgresql/9.6/bin/"; |
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
//+ Jonas Raoni Soares Silva | |
//@ http://raoni.org | |
export default (...values) => Math.max(...values.map(value => | |
(value = (value + '').split(/[.,]/)).length > 1 && value.pop().length | |
)); |
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
//+ Jonas Raoni Soares Silva | |
//@ http://raoni.org | |
export default function debounce (action, delay) { | |
let handle; | |
return function (...args) { | |
if (handle) { | |
clearTimeout(handle); | |
handle = null; | |
} |
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
//+ Jonas Raoni Soares Silva | |
//@ http://raoni.org | |
export default class ServerTime { | |
constructor ({http = new Error('http parameter is required'), url = new Error('url is required'), thresholdDelay = 300, autoSynchronizeProbes = 0}) { | |
Object.assign(this, { | |
http, | |
url, | |
thresholdDelay, | |
best: null |
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
//+ Jonas Raoni Soares Silva | |
//@ http://raoni.org | |
const signalR = require('@aspnet/signalR'); | |
export default class Hub { | |
constructor (url, autoReloadTimeout = 1000) { | |
Object.assign(this, { | |
url, | |
autoReloadTimeout, |
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
/(["'`])(?:\\.|(?!\1).)*?\1/ |
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
//+ Jonas Raoni Soares Silva | |
//@ http://raoni.org | |
function tree(items) { | |
const tree = []; | |
const map = new Map; | |
for (const item of items) { | |
const placeholder = map.get(item.id); | |
item.children = placeholder ? placeholder.children : []; | |
map.set(item.id, item); |