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 curry = (func) => { | |
const arity = func.length; // number of arguments | |
return build = (...args) => { | |
if(args.length >= arity) { // (1) | |
return func(...args); // (3) | |
} | |
else { | |
return build.bind(null, ...args); // (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
const f = (...args) => { | |
console.log(args); // [1, 2] | |
} | |
const g = f.bind(null, 1); | |
g(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
const curry = (func) => { | |
const arity = func.length; // number of arguments | |
return build = (...args) => { | |
if(args.length >= arity) { // (1) | |
return func(...args); // (3) | |
} | |
else { | |
return build.bind(null, ...args); // (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
const curry = (func) => { | |
return (a) => { | |
return (b) => { | |
return (c) => { | |
return func(a, b, c); | |
} | |
} | |
} | |
} |
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 curry = (func) => { | |
return (a) => { | |
return (b) => { | |
return func(a, b); | |
} | |
} | |
} | |
const add = (a, b) => { | |
return a + b; |
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
$input.addEventListener('keydown', e => { | |
if(e.key === 'ArrowRight') { | |
$span.textContent = ''; // clear ghost span | |
$input.textContent = rest + suggestion; // fill the $input bar with required suggestion | |
// moves cursor to the end of the input box (won't go into the details of it) | |
setEndOfContenteditable($input); | |
} | |
}); |
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
/* | |
THIS IS ONLY DONE ONCE | |
there-on we just keep changing the textContent of the $span. | |
*/ | |
const css = getComputedStyle($input); | |
const r = $input.getBoundingClientRect(); // to get the position, width & height of $input | |
const $span = document.createElement('span'); // our ghost span |
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 $fakeDiv = document.getElementById('fake-div'); // used to measure space taken by the query content | |
const main = (e) => { | |
const query = e.target.textContent.toLowerCase(); | |
if(query !== '') { | |
const find_start = new Date().getTime(); | |
/* | |
Ex: |
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 $input = document.getElementById('input'); | |
let INPUT_DEBOUNCE = null; | |
$input.addEventListener('input', e => { | |
clearTimeout(INPUT_DEBOUNCE); | |
$span.textContent = ''; // let's come to this on a later stage, for now pretend it doesn't exist | |
INPUT_DEBOUNCE = setTimeout(() => main(e), 250); | |
}); |
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
<div> | |
<h1>Auto-complete...</h1> | |
<div contenteditable="true" id="input"></div> // our search bar | |
<div id="time"></div> | |
<div id='fake-div' class='div'></div> | |
<script src="index.js"></script> | |
</div> |
NewerOlder