Skip to content

Instantly share code, notes, and snippets.

View CodHeK's full-sized avatar
🤙
Existing

Gagan Ganapathy CodHeK

🤙
Existing
View GitHub Profile
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)
}
const f = (...args) => {
console.log(args); // [1, 2]
}
const g = f.bind(null, 1);
g(2);
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)
}
const curry = (func) => {
return (a) => {
return (b) => {
return (c) => {
return func(a, b, c);
}
}
}
}
const curry = (func) => {
return (a) => {
return (b) => {
return func(a, b);
}
}
}
const add = (a, b) => {
return a + b;
$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 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
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:
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);
});
<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>