This file contains 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
//O(n²) | |
function consecutiveDistance(arr) { | |
let total = 0; | |
for(let i = 0; i < array.length; i++) { | |
for(let j = i + 1; j < array.length; j++) { | |
if(arr[i] === arr[j] - 1 || arr[j] === arr[i] - 1) { | |
total += (j + 1) - (i + 1); | |
} | |
} | |
} |
This file contains 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
h1 = readLine().split(' '); | |
stacks['h1']['array'] = h1.map(Number); | |
h2 = readLine().split(' '); | |
stacks['h2']['array'] = h2.map(Number); | |
h3 = readLine().split(' '); | |
stacks['h3']['array'] = h3.map(Number); | |
function pass() { | |
let max = 0; | |
let maxName = ''; |
This file contains 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
const mongoose = require('mongoose'); | |
const connection = mongoose.connect(process.env.MONGO_URL); | |
const Model = require('./models/model'); | |
//read csv file and save to database | |
const csv = require('csv'); | |
const fs = require('fs'); | |
let file = './objects.csv'; | |
let parser = csv.parse({delimiter: ','},(err, data)=>{ |
This file contains 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
/* The goal of this gist is to try and clarify the following code... */ | |
import { | |
Injectable | |
} from '@angular/core'; | |
import { | |
Observable | |
} from 'rxjs/Observable'; | |
import { | |
Subject | |
} from 'rxjs/Subject'; |
This file contains 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
/* The goal of this gist is to try and clarify the following code... */ | |
import { | |
Injectable | |
} from '@angular/core'; | |
import { | |
Observable | |
} from 'rxjs/Observable'; | |
import { | |
Subject | |
} from 'rxjs/Subject'; |
This file contains 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 Queue { | |
constructor() { | |
this.inStack = []; | |
this.outStack = []; | |
} | |
enqueue(element) { | |
this.inStack.push(element); | |
} | |
dequeue() { | |
if (!this.outStack.length) |
This file contains 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 closingMap = { | |
'{': '}', | |
'[': ']', | |
'(': ')' | |
}; | |
function isBalancedBracketSequence(expression) { | |
var length = expression.length; | |
if (length <= 1 || length % 2 !== 0) { | |
return false; |
This file contains 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
ANSWER: The intention of the code is to hide block letter b, where the target of the anchor tag is NOT blank. However, | |
there is a small typo causing a bug. The original code is as follows: **/ | |
$("div a[target!='_blank"]").hide(); | |
The double quotes after blank cose the selector, causing a bug. The correct code would be: | |
$("div a[target!='_blank']").hide(); | |
Which should work fine. |
This file contains 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
/* | |
1. Write a SQL query that returns names and emails of customers whose credit cards are about to get expired (in the next 14 days). Data model looks like this:* | |
1. Table Customer (id, name, address, email) | |
2. Table CustomerCreditCards(id,customer_id, ccnumber, cvs, expirationdate) | |
*/ | |
SELECT name, email FROM Customer | |
INNER JOIN CustomerCreditCards | |
ON Customer.id = CustomerCreditCards.customer_id | |
WHERE DATEDIFF(CustomerCreditCards.expirationdate,NOW()) <= 14; |
This file contains 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
//2. Write a short javascript function that displays the first non repeating character in a string.Example: If the string is "Alphabet", it would print out the letter "l" | |
function firstUnrepeatedLetter (word){ | |
word = word.toLowerCase(); | |
let hash = {}; | |
for(let char of word){ | |
if(!hash[char]) | |
hash[char] = 1; | |
else | |
hash[char] += 1; | |
} |
NewerOlder