Skip to content

Instantly share code, notes, and snippets.

View jpoechill's full-sized avatar

Po Rith jpoechill

View GitHub Profile
@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
}
// 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 / 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;
}
@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)
[
{
"description": "",
"link": "",
"tags": [
"First tag",
"Second tag"
],
"title": "Official Guide"
},
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 = [];