Skip to content

Instantly share code, notes, and snippets.

View lessmind's full-sized avatar

Ada Chao lessmind

  • Outland Inc
  • Taipei, Taiwan
View GitHub Profile
<?php
function weight($arr) {
if(count($arr) == 1) {
return array_keys($arr)[0];
}
$size = count($arr)/3;
$a = array_slice($arr, 0, $size, true);
$b = array_slice($arr, $size, $size, true);
if(($sumA = array_sum($a)) == ($sumB = array_sum($b))) {
return weight(array_slice($arr, $size*2, null, true));
/**
* @param {number[]} numbers
* @param {number} target
* @return {number[]} two integers in an array, ie: [index1, index2]
*/
var twoSum = function(numbers, target) {
var max = numbers.length, map = {};
for(var i = 0; i < max; i++) {
if(map[numbers[i]] !== undefined) {
return [map[numbers[i]]+1, i+1];
@lessmind
lessmind / proxy-testing.js
Last active May 15, 2018 19:25
proxy testing
var http = require('http'),
https = require('https'),
URL = require('url');
var request = function(name, url, proxy) {
// options
var options = URL.parse(url, false);
// headers
options.headers = {
accept: '*/*',