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 image_coordinates = (img) =>{ | |
document.querySelector(img).addEventListener('click', (event) =>{ | |
let target = event.currentTarget.getBoundingClientRect(), | |
target_w = target.width, | |
target_h = target.height, | |
target_x = target.left, | |
target_y = target.top, | |
x_pos = event.clientX, | |
y_pos = event.clientY; |
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
//passing i to an anonymous self executing funtion will bind event handlers to DOM nodes from IE9 and up. Haven't checked for IE9 and below. | |
for (let i = 0; i < el.length; i++) { | |
(function(i){ | |
el[i].addEventListener('click', (event) => { | |
}); | |
})(i); | |
} |
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 stringPosition(needle, haystack) { | |
var m = needle.length, | |
n = haystack.length; | |
if (!m || !n || m > n) { | |
return -1; | |
} | |
if (m === n) { | |
return needle === haystack ? 0 : -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
const jsonObject = { | |
//key values | |
} | |
const xhttp = new XMLHttpRequest(); | |
xhttp.onreadystatechange = function() { | |
if (this.readyState == 4 && this.status == 200) { | |
//on complete | |
} | |
} |
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
// WARNING: SIDE-EFFECTS. ONLY FOR PROD VERSION | |
if (!__DEV__) { | |
require('./utils/log.js'); | |
} | |
// SIDE-EFFECTS END |
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
/* | |
Write a function that reverses a string. The input string is given as an array of characters char[]. | |
Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. | |
You may assume all the characters consist of printable ascii characters. | |
*/ | |
const arr = ["h", "e", "l", "l", "o"] |
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. Understanding the problem | |
a. Can you restate the problem in your own words? | |
b. What are the input that go into the problem? | |
c. What are teh outputs that should come from the solution of the problem? | |
d. Do you have enough information to solve the problem? | |
e. What should you label the important pieces of data in the problem? | |
2. Create Examples | |
3. Break it down | |
a. Write downs steps of problem in a comment latter | |
4. Solve or Simplify |
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
// Cleaner way to manage state and its handlers | |
import React, { useState, useMemo } from 'react'; | |
const Home = (props) => { | |
const [count, { inc, dec }] = useCounter(); | |
return ( | |
<main id="home-component" className="component-container"> | |
<h5>Count {count}</h5> |
OlderNewer