This file contains hidden or 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
| /*Given a non-empty list of words, return the k most frequent elements. | |
| Your answer should be sorted by frequency from highest to lowest. If two words have the same frequency, then the word with the lower alphabetical order comes first. | |
| Example 1: | |
| Input: ["i", "love", "leetcode", "i", "love", "coding"], k = 2 | |
| Output: ["i", "love"] | |
| Explanation: "i" and "love" are the two most frequent words. | |
| Note that "i" comes before "love" due to a lower alphabetical order. | |
| Example 2: |
This file contains hidden or 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
| var combinations = function(str) { | |
| var arr = str.split(''); | |
| for( var i=0; i< arr.length; i++){ | |
| genComb(arr, i+1); | |
| } | |
| } | |
| function genComb(arr, length, str, index) { | |
| str = str || ''; | |
| index = index || 0; |
This file contains hidden or 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
| var traverseDOM = function(node, fn) { | |
| fn(node); | |
| node = node.firstChild; | |
| while(node) { | |
| traverseDOM(node, fn); | |
| node = node.nextSibling; | |
| } | |
| } | |
This file contains hidden or 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
| var debounce = function(fn, time, immediate) { | |
| var timeout; | |
| return function() { | |
| var that = this; | |
| var args = arguments; | |
| var later = function() { | |
| if(!immediate){ | |
| timeout = null; | |
| func.call(that, args); |
This file contains hidden or 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
| var flattenArray = function(arr) { | |
| var results = []; | |
| arr.forEach(function(item) { | |
| if(Array.isArray(item)) { | |
| results = results.concat(flattenArray(item)); | |
| } else { | |
| results.push(item); | |
| } | |
| }); | |
| return results; |
This file contains hidden or 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 java.util.ArrayList; | |
| import java.util.HashMap; | |
| import java.util.Map; | |
| import java.util.Scanner; | |
| public class TriesContacts { | |
| static class Node { | |
| HashMap<Character, Node> links = null; | |
| boolean isFinish; |
This file contains hidden or 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
| var myPromise = new Promise((resolve, reject) => { | |
| setTimeout(() => { | |
| resolve(10); | |
| }, 1000); | |
| }); | |
| // handler can't change promise, just value | |
| myPromise.then((result) => { | |
| console.log(result); | |
| }).catch((err) => { |
This file contains hidden or 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
| var value1 = 100; | |
| let value2 = 100; | |
| { | |
| var value1 = 200 | |
| let value2 = 200 | |
| } | |
| console.log(value1); // 200 | |
| console.log(value2); // 100 |
This file contains hidden or 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
| var state1 = { | |
| val1 : 'abc', | |
| val2: 'xyz' | |
| }; | |
| var state2 = { | |
| val2 : 'mno', | |
| val3: 'xyz' | |
| }; |
This file contains hidden or 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
| // rest param example | |
| var multipleInputs = function (value, ...restParamValues ) { | |
| restParamValues.forEach( function(paramVal){ | |
| // do something with paramVal | |
| }); | |
| } |
NewerOlder