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
/(.*?)/g | |
// (.*?) is ungreedy |
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 quickSort = list => { | |
if (list.length < 2) | |
return list; | |
let pivot = list[0]; | |
let left = []; | |
let right = []; | |
for (let i = 1, total = list.length; i < total; i++){ | |
if (list[i] < pivot) | |
left.push(list[i]); | |
else |
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
// assuming el is dom object | |
function checkVisible(el) | |
{ | |
return el.offsetTop < window.innerHeight + window.pageYOffset | |
} |
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 time = 3600 //second 1 hour | |
var minutes = Math.floor(time / 60); | |
//And to get the remaining seconds, multiply the full minutes with 60 and subtract from the total seconds: | |
var seconds = time - minutes * 60; | |
//Now if you also want to get the full hours too, divide the number of total seconds by 3600 (60 minutes/hour · 60 seconds/minute) first, then calculate the remaining seconds: | |
var hours = Math.floor(time / 3600); |
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
import React, { useState } from "react"; | |
import ReactDOM from "react-dom"; | |
import { Transition } from "react-transition-group"; | |
import "./styles.css"; | |
function App() { | |
const [visible, setVisible] = useState(true); | |
return ( |
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 fibonacci(num){ | |
var a = 1, b = 0, temp; | |
while (num >= 0){ | |
temp = a; | |
a = a + b; | |
b = temp; | |
num--; | |
} |
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
mport React from 'react'; | |
import { shallow, mount, render } from 'enzyme'; | |
import Todo from '../components/Todo'; | |
import { configure } from 'enzyme'; | |
import Adapter from 'enzyme-adapter-react-16'; | |
configure({ adapter: new Adapter() }); | |
test('Test it', async () => { |
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 //->true | |
1 == "1" //->true | |
1 == true//-> true | |
1 == 0 //-> false | |
1 == [] //-> false |
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
// basic | |
var max = 250 | |
var min = 50 | |
var input = 65 | |
var percent = ((input - min) * 100) / (max - min) | |
// a little longer | |
var range = max - min | |
var correctedStartValue = input - min | |
var percentage = (correctedStartValue * 100) / range |
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 url = 'auth/user/ucok'; | |
const lastStr = url.split("/").slice(-1)[0]; | |
// output 'ucok' |
NewerOlder