const elements = { button: document.getElementById('button'), image: document.getElementById('image'), text: document.getElementById('text') }; const doStuff = () => { image.src = 'http://some.url/image'; button.click(); console.log(text.innerHTML); // Much more logic } const removeButton = () => { // The button is a direct child of body. document.body.removeChild(document.getElementById('button')); // At this point, we still have a reference to #button in the global // elements dictionary. In other words, the button element is still in // memory and cannot be collected by the GC. }
var minTime = function(time, m) { if(time.length <= m) { return0 } let l = 0 let r = Number.MAX_VALUE while(l < r) { let mid = Math.floor(l + (r - l) / 2) if(canS(time, m, mid)) { r = mid } else { l = mid + 1 } } return r };
var canS = function(time, m, mid) { let sum = 0 let count = 0 let maxt = 0 for( let t of time) { sum = sum + t maxt = Math.max(maxt, t) if(sum - maxt > mid) { if( ++count == m) { returnfalse } sum = t maxt = t } } returntrue }
var minSteps = function(s, t) { let map = newMap(), ans = 0; for (let i = 0, len = s.length; i < len; i++) { let c = s.charAt(i) if (!map.has( c )) { map.set( c, 1 ) } else { map.set( c, map.get( c ) + 1 ) } } for (let i = 0, len = t.length; i < len; i++) { let c = t.charAt(i) if (map.has( c )) { map.set( c, map.get( c ) - 1 ) } } map = [...map] for (let i = 0, len = map.length; i < len; i++) { if (map[i][1] > 0) { ans += map[i][1] } } return ans }