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
calculateDOMDepth = (doc = document)-> | |
max = 0 | |
_calculateDOMDepth = (dom)-> | |
domdepth = dom.dataset.domdepth = parseInt(dom.parentNode.dataset.domdepth) + 1 | |
max = domdepth if domdepth > max | |
Array.prototype.forEach.call dom.children, (child)-> | |
_calculateDOMDepth(child) | |
body = doc.body | |
body.parentNode.dataset.domdepth = 0 | |
_calculateDOMDepth(body) |
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
getDaysByMonth = (date = new Date(), fill=true, chinese = true) -> | |
date.setDate(1) | |
day = date.getDay() | |
month = date.getMonth() | |
days = [] | |
while date.getMonth() == month | |
days.push new Date(date.getTime()) | |
date.setDate(date.getDate() + 1) | |
monthCount = days.length | |
if fill |
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
str = "" | |
for i in [0x0000..0xffff] | |
str += String.fromCharCode(i) | |
console.log str | |
### | |
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴǵǶǷǸǹǺǻǼǽǾǿȀȁȂȃȄȅȆȇȈȉȊȋȌȍȎȏȐȑȒȓȔȕȖȗȘșȚțȜȝȞȟȠȡȢȣȤȥȦȧȨȩȪȫȬȭȮȯȰȱȲȳȴȵȶȷȸȹȺȻȼȽȾȿɀɁɂɃɄɅɆɇɈɉɊɋɌɍɎɏɐɑɒɓɔɕɖɗɘəɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼʽʾʿˀˁ˂˃˄˅ˆˇˈˉˊˋˌˍˎˏːˑ˒˓˔˕˖˗˘˙˚˛˜˝˞˟ˠˡˢˣˤ˥˦˧˨˩˪˫ˬ˭ˮ˯˰˱˲˳˴˵˶˷˸˹˺˻˼˽˾˿̴̵̶̷̸̡̢̧̨̛̖̗̘̙̜̝̞̟̠̣̤̥̦̩̪̫̬̭̮̯̰̱̲̳̹̺̻̼͇͈͉͍͎̀́̂̃̄̅̆̇̈̉̊̋̌̍̎̏̐̑̒̓̔̽̾̿̀́͂̓̈́͆͊͋͌̕̚ͅ͏͓͔͕͖͙͚͐͑͒͗͛ͣͤͥͦͧͨͩͪͫͬͭͮͯ͘͜͟͢͝͞͠͡ͰͱͲͳʹ͵Ͷͷͺͻͼͽ;Ϳ΄΅Ά·ΈΉΊΌΎΏΐΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩΪ |
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
maxHeapify = (arr, i, heapSize)-> | |
left = i * 2 + 1 | |
right = i * 2 + 2 | |
largest = i | |
if left < heapSize && arr[i] < arr[left] | |
largest = left | |
if right < heapSize && arr[largest] < arr[right] | |
largest = right | |
if largest isnt i | |
temp = arr[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
quickSort = (arr)-> | |
debugger | |
return arr if arr.length < 2 | |
left = [] | |
right = [] | |
for i in [1...arr.length] | |
if arr[0] > arr[i] | |
left.push arr[i] | |
else | |
right.push arr[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
selectionSort = (arr)-> | |
for i in [0...arr.length - 1] | |
min = arr[i] | |
minI = i | |
for j in [i+1...arr.length] | |
if min > arr[j] | |
minI = j | |
if i isnt minI | |
temp = arr[i] | |
arr[i] = arr[minI] |
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
insertSort = (arr)-> | |
for i in [1...arr.length] | |
for j in [i-1..0] | |
if arr[j] > arr[j+1] | |
temp = arr[j] | |
arr[j] = arr[j+1] | |
arr[j+1] = temp | |
arr | |
#test |
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
bubbleSort = (arr)-> | |
return arr if arr.length <= 1 | |
for i in [arr.length...1] | |
for j in [0...i-1] | |
if arr[j] > arr[j+1] | |
temp = arr[j] | |
arr[j] = arr[j+1] | |
arr[j+1] = temp | |
arr | |
#test |
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
merge = (left, right)-> | |
i = j = 0 | |
arr =[] | |
while i < left.length || j < right.length | |
if i is left.length | |
arr = arr.concat right.slice j, right.length | |
break | |
if j is right.length | |
arr = arr.concat left.slice i, right.length | |
break |
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
#https://developer.mozilla.org/en-US/docs/JavaScript/ECMAScript_6_support_in_Mozilla | |
Map = Map || do -> | |
id = 0 | |
keyToObj = {} | |
keyToValue = {} | |
unique = -> | |
"Map_#{id++}" | |
getKeyByObj = (obj)-> | |
for own key, value of keyToObj | |
if obj is value |