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
// Type and StructType both inherit Napi::ObjectWrap. | |
// And they both have a static member called constructor `static inline Napi::FunctionReference constructor;` | |
void StructType::Init(Napi::Env env, Napi::Object &exports) { | |
Napi::HandleScope scope(env); | |
Napi::Function super_func = Type::constructor.Value(); | |
napi_value super_ctor = napi_value(super_func); | |
Napi::Function func = DefineSubClass(env, super_ctor, "StructType", { | |
StaticMethod("create", &StructType::create), | |
InstanceMethod("setBody", &StructType::setBody) | |
}); |
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 data = { | |
cities: [ | |
["New York", 40.66361111111111, -73.93861111111111], | |
["Los Angeles", 34.019444444444446, -118.41083333333334], | |
["Chicago", 41.837500000000006, -87.68166666666667], | |
["Houston", 29.78666666666667, -95.39083333333333], | |
["Phoenix", 33.57222222222222, -112.08999999999999], | |
["Philadelphia", 40.00944444444445, -75.13333333333334], | |
["San Antonio", 29.472499999999997, -98.525], | |
["San Diego", 32.81527777777777, -117.135], |
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
int maxSubSequence(int arr[], int n) | |
{ | |
int sum = 0, maxSum = 0; | |
for (int i = 0; i < n; i++) | |
{ | |
sum += arr[i]; | |
if (sum > maxSum) | |
maxSum = sum; | |
else if (sum < 0) | |
{ |
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
#include <iostream> | |
#include <math.h> | |
using namespace std; | |
//------------------------------------------------------------------------------------- | |
// 直接插入排序 | |
void insertionSort(int arr[], int n, int g) | |
{ | |
for (int i = g; i < n; i++) | |
{ |
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 fs = require('fs'); | |
function copy(src, dst) { | |
//小文件拷贝 | |
fs.writeFileSync(dst,fs.readFileSync(src)); | |
//大文件拷贝 | |
//fs.createReadStream(src).pipe(fs.createWriteStream(dst)); | |
} | |
function main(argv) { | |
copy(argv[0], argv[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
function gcd(x, y) { | |
while (y) { | |
[x, y] = [y, x % y]; | |
} | |
return x; | |
} | |
const lcm = (x,y) => x * y / gcd(x,y); | |
function multipleLCM(...nums) { |
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
function generatePrimesList(num) { | |
let ret = []; | |
if (num >= 2) | |
ret.push(2); | |
for (let i = 3; i <= num; i++) { | |
let flag = true; | |
for (let j = 0; j < ret.length; j++) { | |
if (i % ret[j] === 0) { | |
flag = false; | |
break; |
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
function convert(num) { | |
// suppose num>0&&num<4000000 | |
if(!Number.isInteger(num)) { | |
throw 'Sorry, there are only integers in Rome numerals.'; | |
} else if(num<0) { | |
throw 'Sorry, there is no negative in Roman numerals.'; | |
} else if(num===0) { | |
throw 'Sorry, there is no zero in Roman numerals.'; | |
} else if(num>=4000000) { | |
throw 'Sorrt, 4000000 and more are too high.'; |