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
/** | |
* A priority queue stores a list of items but each can have a numeric priority value. | |
* Items with a higher priority are dequeued before items with a lower priority. | |
* Implemented as a hash of arrays where the hash keys are priority values. | |
*/ | |
function PriorityQueue() { //removed unused size variable | |
this.store = {}; // keys are priorities, values are arrays of elements | |
this.count = 0; | |
// either keep all the functions inside Priority Queue or outside. | |
// only keep properties of object inside constructor and define the Object properties on the prototype function so that its easy to read and follow the code. |
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 peak(arr) { | |
let leftsum = 0; | |
let rightsum = 0; | |
mid = Math.floor(arr.length / 2) | |
const hash = {} | |
while (mid > 0) { | |
leftsum = 0; | |
rightsum = 0; | |
for (x = mid - 1; x >= 0; x--) { | |
leftsum += arr[x] |
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 validSolution(board) { | |
let valid = true; | |
const testvaliditiy = (arr) => { | |
let set = new Set(arr); | |
if (arr.includes(0) || [...set].length !== 9) { | |
return false; | |
} else { | |
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 callApi(url){ | |
return new Promise((resolve,reject) => { | |
console.log(`calling API: ${url}`) | |
if(url==='twitter'|| url=='facebook'){ | |
resolve(`connected to ${url}`) | |
} | |
else{ | |
reject(`Sorry unsupported API : ${url}`) | |
} | |
}); |
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
class Address{ | |
constructor(street,city,country){ | |
this.street = street; | |
this.city = city; | |
this.country = country; | |
} | |
} | |
class User{ |
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 sortByName(arr) { | |
let ones= ['zero','one','two','three','four','five','six','seven','eight','nine','ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen']; | |
let tens = ['','','twenty','thirty','fourty','fifty','sixty','seventy','eighty','ninety'] | |
let alphanums = {} | |
arr.forEach((v,i)=>{ | |
let numstring = String(v) | |
numstring =numstring.split('').reverse('').join(''); | |
let len= numstring.length; | |
let str='' | |
let x= 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
function domainName(url){ | |
if(url.search('//')>0){ | |
url = url.slice(url.search('//')+2); | |
} | |
if(url.search('www')>=0){ | |
url = url.slice(url.search('www')+4); | |
} | |
return url.slice(0,url.indexOf('.')); | |
} |
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
#!/bin/bash | |
var1='A' | |
var2='B' | |
my_function () { | |
local var1='C' | |
var2='D' | |
echo "Inside function: var1: $var1, var2: $var2" | |
} |
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
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
name: mynode-app | |
namespace: nodejs | |
spec: | |
replicas: 2 | |
selector: | |
matchLabels: | |
app: mynode-app |
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
apiVersion: v1 | |
kind: Service | |
metadata: | |
name: mynode-app | |
namespace: nodejs | |
spec: | |
selector: | |
app: mynode-app | |
ports: | |
- port: 80 |
OlderNewer