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
const Promise = require('bluebird'); | |
const readFile = Promise.promisify(require('fs').readFile); | |
const fileList = ['file1.txt', 'file2.txt', 'file3.txt']; | |
const promises = fileList.map((filename) => { | |
return readFile(filename); | |
}); | |
Promise.all(promises) | |
.then((contents) => { |
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
var chai = require('chai'); | |
var expect = chai.expect; | |
describe('Test Pascals Traiangle', function() { | |
it('Test numRows = 0', function() { | |
var numRows = 0; | |
var result = generate(numRows); | |
expect(result).to.deep.equal([]); | |
}); |
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
/** | |
* @param {number} numRows | |
* @return {number[][]} | |
*/ | |
var generate = function(numRows) { | |
if (numRows === 0) return []; | |
var arr = [[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
+---+---+---+---+---+---+ | |
| | 0 | 1 | 2 | 3 | 4 | | |
| 0 | 1 | | | | | | |
| 1 | 1 | 1 | | | | | |
| 2 | 1 | 2 | 1 | | | | |
| 3 | 1 | 3 | 3 | 1 | | | |
| 4 | 1 | 4 | 6 | 4 | 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
var chai = require('chai'); | |
var expect = chai.expect; | |
describe('Test Quick Sort', function() { | |
it('Expect 4 is true', function() { | |
var input = 4; | |
var result = isPowerOfFour(input); | |
expect(result).to.be.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
/** | |
* @param {number} num | |
* @return {boolean} | |
*/ | |
var isPowerOfFour = function(num) { | |
if (num === 1) return true; | |
var mStr = num.toString(4); | |
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
var chai = require('chai'); | |
var expect = chai.expect; | |
describe('Test intersection', function() { | |
it('Expect input [1, 2, 2, 1] and [2, 2] will equal [2]', function() { | |
var nums1 = [1, 2, 2, 1]; | |
var nums2 = [2, 2]; | |
var result = intersection(nums1, nums2); | |
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
/** | |
* @param {number[]} nums1 | |
* @param {number[]} nums2 | |
* @return {number[]} | |
*/ | |
var intersection = function(nums1, nums2) { | |
var isExistArray = [false, false, false, false, false, false, false, false, false, false]; | |
var result = []; |
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
var chai = require('chai'); | |
var expect = chai.expect; | |
describe('Test Find The Difference', function() { | |
it('Test1', function() { | |
var string1 = "abc"; | |
var string2 = "abct" | |
var result = findTheDifference(string1, string2); | |
expect(result).to.equal("t"); |
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
/** | |
* @param {string} string1 | |
* @param {string} string2 | |
* @return {string} | |
*/ | |
var findTheDifference = function(string1, string2) { | |
var mStr = 'abcdefghijklmnopqrstuvwxyz'; | |
for (var i=0; i<mStr.length; i++) { |