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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Document</title> | |
<style> | |
body{ | |
font-size: 150px; | |
} |
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 forEach(array, iteratee) { | |
let index = -1; | |
const length = array.length; | |
while (++index < length) { | |
iteratee(array[index], index); | |
} | |
return array; | |
} | |
function clone(target, map = new WeakMap()) { |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title>Document</title> | |
<style> | |
body, button{ | |
font-size: 30px; | |
} | |
.red{ | |
color: red; |
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 inBrowser = typeof window !== 'undefined' | |
const inWeex = typeof WXEnvironment !== 'undefined' && !!WXEnvironment.platform | |
const weexPlatform = inWeex && WXEnvironment.platform.toLowerCase() | |
const UA = inBrowser && window.navigator.userAgent.toLowerCase() | |
const isIE = UA && /msie|trident/.test(UA) | |
const isIE9 = UA && UA.indexOf('msie 9.0') > 0 | |
const isEdge = UA && UA.indexOf('edge/') > 0 | |
const isAndroid = (UA && UA.indexOf('android') > 0) || (weexPlatform === 'android') | |
const isIOS = (UA && /iphone|ipad|ipod|ios/.test(UA)) || (weexPlatform === 'ios') | |
const isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge |
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 isNative (Ctor){ | |
return typeof Ctor === 'function' && /native code/.test(Ctor.toString()) | |
} |
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 countFrequency(arr){ | |
let result = new Map(); | |
for(let element of arr){ | |
if(result.get(element)) { | |
result.set(element, result.get(element) + 1) | |
} else { | |
result.set(element, 1) | |
} | |
} | |
return result; |
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
// Get the price of apples from a fruit store | |
function getApplePrice(fruitStore) { | |
'start visiting the fruit store'; | |
'walk to the fruit shop'; | |
if('the fruit store was not open'){ | |
'stop the process of visiting the fruit store'; | |
return 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
'the apple purchase process begins'; | |
'Declare a variable `lowestPriceFruitStore`, used to represent the fruit store with the lowest apple prices.'; | |
for(fruitStore of [fruitStroe0, fruitStroe1, fruitStroe2]){ | |
'start visiting the fruit store'; | |
'walk to the fruit shop'; | |
if('the fruit store was not open'){ | |
'stop the process of visiting the fruit store'; | |
} |
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
'the apple purchase process begins'; | |
// try to visit these 3 fruit stores in turn | |
for(fruitStore of [fruitStroe0, fruitStroe1, fruitStroe2]){ | |
'start visiting the fruit store'; | |
'walk to the fruit shop'; | |
if('the fruit store was not open'){ | |
'stop the process of visiting the fruit store'; | |
} |
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
class MyPromise{ | |
constructor(executor) { | |
this.status = "pending"; | |
this.value = undefined; | |
// This array is used to store all the onResolve functions in the chain call | |
this.resolveArr = []; | |
// // This array is used to store all the onReject functions in the chain call | |
this.rejectArr = []; |