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
| //reverse string | |
| function solution(str){ | |
| if(str === "") return ""; | |
| return solution(str.substr(1,str.length-1)) + str[0]; | |
| } | |
| //fibonacci numbers | |
| function fibonacci(num) { |
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
| //spiral | |
| var spiral = function(n){ | |
| var direction; | |
| x=0 | |
| y=0 | |
| resultArray = [[0,0]] | |
| for (var k=1; k < n; k++){ | |
| direction = k%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
| //All, none, any | |
| Array.prototype.all = function (p) { | |
| return this.length > 0 && this.filter(p).length === this.length; | |
| }; | |
| Array.prototype.none = function (p) { | |
| return this.filter(p).length === 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
| //find count of most frequent item in array | |
| function mostFrequentItemCount(store) { | |
| var frequency = {} | |
| var max = 0; | |
| var result; | |
| for (var v in store) { | |
| frequency[store[v]] = (frequency[store[v]] || 0)+1; | |
| if(frequency[store[v]] > max) { | |
| max = frequency[store[v]]; | |
| // result = store[v]; |
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
| //detect pangram (has all alphabet characters) | |
| function isPangram(string){ | |
| var alphabets = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z" | |
| var a = alphabets.split(",") | |
| string = string.replace(/[^a-zA-Z0-9]+/g,"").toLowerCase() | |
| for(var i=0;i<a.length;i++) { | |
| if(string.indexOf(a[i]) === -1) return false; | |
| } | |
| return true; | |
| } |
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
| function count(file) { | |
| var lines = file.split("\n") | |
| var wordToCounterMap = {} | |
| var wordToLineMap = {} | |
| for(var k = 0; k < lines.length; k++) { | |
| countWords(lines[k].split(" "), k) | |
| } | |
| function countWords(words, lineNumber) { |
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
| function mergeIntervals(intervals) { | |
| if(intervals.length < 2) return intervals | |
| intervals = intervals.sort(function(a,b) { | |
| return a[0] - b[0] | |
| }) | |
| var stack = [] | |
| stack.push(intervals[0]) | |
| var top | |
| for(var i = 1; i < intervals.length; i++) { | |
| top = stack[stack.length - 1] |
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
| function anagram(str) { | |
| var obj = {} | |
| function recurse(combo, feed) { | |
| if(!feed.length) { | |
| obj[combo] = 1 | |
| return | |
| } else { | |
| for(var i=0; i < feed.length; i++) { | |
| recurse(combo+feed[i], feed.slice(0,i) + feed.slice(i+1)) | |
| } |
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
| function rps(rounds) { | |
| var obj = {} | |
| var feed = ['r','p','s']; | |
| function recurse(combo, numRoundsLeft) { | |
| if(!numRoundsLeft) { | |
| obj[combo] = 1 | |
| return | |
| } | |
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
| async function sendSignedTransaction(web3, privateKey, nonce, gasPrice, gasLimit, to, from, data) { | |
| try { | |
| const rawTx1 = { | |
| nonce: nonce, | |
| gasPrice: gasPrice, | |
| gasLimit: gasLimit, | |
| to: to, | |
| from: from, | |
| data: data |
OlderNewer