Skip to content

Instantly share code, notes, and snippets.

View jpoechill's full-sized avatar

Po Rith jpoechill

View GitHub Profile
var text = `
vue-cli - Simple CLI for scaffolding Vue.js projects.
Vue Plugin Boilerplate - Boilerplate for Vue.js plugin.
Bourgeon - Bourgeon is an opinionated-featured VueJS 2.0 setup for Webpack.
VuePack - A modern starter which uses Vue 2, Vuex, Vue-router and Webpack 2 (and even Electron).
`
text = text.trim().split("\n");
var object = {}
var items = [];
[
{
"description": "",
"link": "",
"tags": [
"First tag",
"Second tag"
],
"title": "Official Guide"
},
@jpoechill
jpoechill / HNrecursive
Created April 10, 2017 22:03
HN, get all posts' kids (recursive)
var val = fetchAllKids('9153')
// console.log(val);
function fetchAllKids(link, parent){
var uniqueID = link
var localLink1 = 'https://hacker-news.firebaseio.com/v0/item/' + uniqueID + '.json?'
axios.get(localLink1, uniqueID)
@jpoechill
jpoechill / linkedlists-fem.js
Created May 12, 2017 06:34
Linked Lists via. FEM
function Node (value) {
this.next = null;
this.value = value;
}
function LinkedList (headValue) {
if (headValue === undefined) console.log("Head must be defined");
this.head = new Node(headValue);
this.tail = this.head;
}
// Codefights Prompt
You have a list of dishes. Each dish is associated with a list of ingredients used to prepare it. You want to to group the dishes by ingredients, so that for each ingredient you'll be able to find all the dishes that contain it (if there are at least 2 such dishes).
Return an array where each element is a list with the first element equal to the name of the ingredient and all of the other elements equal to the names of dishes that contain this ingredient. The dishes inside each list should be sorted lexicographically. The result array should be sorted lexicographically by the names of the ingredients in its elements.
Example
For
dishes = [["Salad", "Tomato", "Cucumber", "Salad", "Sauce"],
["Pizza", "Tomato", "Sausage", "Sauce", "Dough"],
@jpoechill
jpoechill / sumOfTwo.js
Last active May 25, 2017 04:16
sumOfTwo via. Web
function sumOfTwo(a, b, v) {
a.sort()
b.sort()
for(i in a) {
var target = v - a[i]
if (binary_Search(b, target) > -1) {
console.log(target)
return true
}
@jpoechill
jpoechill / repeatedDNASequences
Created May 24, 2017 04:22
repeatedDNASequences via. CodeFights
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T. In research, it can be useful to identify repeated sequences within DNA.
Write a function to find all the 10-letter sequences (substrings) that occur more than once in a DNA molecule s, and return them in lexicographical order. These sequences can overlap.
Example
For s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT", the output should be
repeatedDNASequences(s) = ["AAAAACCCCC", "CCCCCAAAAA"].
Input/Output
@jpoechill
jpoechill / appleStocks.js
Last active May 25, 2017 04:15
Apple Stocks via. InterviewCake
function getMaxProfit(stockPrices) {
var allPurchases = {}
var allPurchasesArr = []
for (var i = 0; i < (stockPrices.length); i++) {
var stockClone = stockPrices.slice(0)
var currRemoved = stockClone.splice(0, i+1)
var maxStockRight = Math.max(...stockClone)
allPurchases[stockPrices[i]] = stockPrices[i] - maxStockRight
@jpoechill
jpoechill / getProductsOfAllIntsExceptAtIndex.js
Last active May 25, 2017 04:58
Product of All Other Numbers via. InterviewCake
function getProductsOfAllIntsExceptAtIndex (arr) {
var productsOfArr = []
for (var i = 0; i < arr.length; i++) {
var clone = arr.slice(0)
var removed = clone.splice(i, 1)
productsOfArr.push(getProductOfArr(clone));
}
@jpoechill
jpoechill / mergedMeetings.js
Created May 30, 2017 00:02
Merged Meetings via. Interview Cake
// Final solution
function mergeRanges (meetings) {
// sort by start time
var sortedMeetings = meetings.slice().sort(function (a, b) {
return a.startTime > b.startTime ? 1: -1
})
// initialize meetings with first from sorted meetings
var mergedMeetings = [sortedMeetings[0]]