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
    
  
  
    
  | // sequence of functions that you want to be invoked for a specific value | |
| const pipe = (...fns) => x => fns.reduce((v, f) => f(v), x); | |
| // nvokes the functions in reverse order | |
| const compose = (...fns) => x => fns.reverse().reduce((v, f) => f(v), x); | |
| /* | |
| // example: calculating the checkout total | |
| const calculateTotal = pipe( | 
  
    
      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
    
  
  
    
  | // Use the browser's built-in functionality to quickly and safely escape | |
| // the string | |
| function escapeHtml(str) { | |
| var div = document.createElement('div'); | |
| div.appendChild(document.createTextNode(str)); | |
| return div.innerHTML; | |
| } | 
  
    
      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
    
  
  
    
  | (function(){ | |
| //https://en.wikipedia.org/wiki/Year_2038_problem | |
| return new Date(0x7fffffff * 1e3); | |
| /** | |
| * is the maximum number of seconds elapsed | |
| * since 1 January 1970 00:00:00 UTC | |
| * expressible by a signed 32-bit integer | |
| */ | |
| })(); | 
  
    
      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
    
  
  
    
  | function* fibonacci() { // una función generador | |
| let [prev, curr] = [0, 1]; | |
| while (true) { | |
| [prev, curr] = [curr, prev + curr]; | |
| yield curr; | |
| } | |
| } | |
| for (let n of fibonacci()) { | |
| console.log(n); | 
  
    
      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
    
  
  
    
  | function* genFunc(){ //looks synchronously written | |
| var post1title = yield fetch("https://jsonplaceholder.typicode.com/posts/1"); | |
| console.log(post1title); | |
| //post1title = "sunt aut facere repellat provident occaecati excepturi optio reprehenderit" | |
| var post2title = yield fetch("https://jsonplaceholder.typicode.com/posts/2"); | |
| console.log(post2title); | |
| //post2title = "qui est esse" | |
| } | 
  
    
      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
    
  
  
    
  | function run(genFunc){ | |
| const genObject= genFunc(); //creating a generator object | |
| function iterate(iteration){ //recursive function to iterate through promises | |
| if(iteration.done) //stop iterating when done and return the final value wrapped in a promise | |
| return Promise.resolve(iteration.value); | |
| return Promise.resolve(iteration.value) //returns a promise with its then() and catch() methods filled | |
| .then(x => iterate(genObject.next(x))) //calls recursive function on the next value to be iterated | |
| .catch(x => iterate(genObject.throw(x))); //throws an error if a rejection is encountered | |
| } | 
  
    
      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
    
  
  
    
  | var initObject = { | |
| method: 'POST', | |
| headers: new Headers(), | |
| mode: 'cors', | |
| body: "{}" | |
| } | |
| var request = new Request("https://jsonplaceholder.typicode.com/posts",initObject) | |
| //first time using Request object | 
  
    
      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
    
  
  
    
  | <a download="somedata.csv"href="data:application/csv;charset=utf-8,Col1%2CCol2%2CCol3%0AVal1%2CVal2%2CVal3%0AVal11%2CVal22%2CVal33%0AVal111%2CVal222%2CVal333">Example</a> | 
  
    
      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
    
  
  
    
  | // Returns a function, that, as long as it continues to be invoked, will not | |
| // be triggered. The function will be called after it stops being called for | |
| // N milliseconds. If `immediate` is passed, trigger the function on the | |
| // leading edge, instead of the trailing. | |
| function debounce(func, wait, immediate) { | |
| var timeout; | |
| return function() { | |
| var context = this, args = arguments; | |
| var later = function() { | |
| timeout = null; | 
  
    
      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
    
  
  
    
  | Math.random().toString(36).substr(2, 8); | |
| //one step beyond | |
| btoa(Math.random().toString(36).substr(2, 8)); | 
NewerOlder