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
| package main | |
| import ( | |
| "fmt" | |
| "log" | |
| "net/http" | |
| ) | |
| type Configs struct { | |
| Addr string |
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
| package main | |
| import ( | |
| "fmt" | |
| ) | |
| // https://www.codewars.com/kata/51e0007c1f9378fa810002a9/train/go | |
| func main() { | |
| input := "idoiido" |
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
| package main | |
| import "fmt" | |
| func main() { | |
| fmt.Println(findPairs([]int{1, 2, 3, 4, 5}, 3)) | |
| } | |
| func findPairs(nums []int, target int) [][]int { |
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
| // instruction: find the highest sum of sequence values from sub slice from the given slice | |
| package main | |
| import "fmt" | |
| func main() { | |
| input1 := []int{1, -1, 0, 3, 4, -3, 2} |
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 data = [5, 8, 11, 19, 7, 15, 12, 20, 10, 1, 6, 3]; | |
| // sorting function | |
| const merge = (arr1, arr2) => { | |
| let sorted = []; | |
| while (arr1.length && arr2.length) { | |
| if (arr1[0] < arr2[0]) sorted.push(arr1.shift()); | |
| else sorted.push(arr2.shift()); | |
| } |
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
| // O(logN) | |
| // Collection must be in sorted order, merge sort and binary search are the great implementation. | |
| function recursiveFn(arr, x, startIndex, endIndex){ | |
| // ends recursive fn when nothing left to searching for. | |
| if(startIndex > endIndex) return false; | |
| // find the middle index | |
| let mid = Math.floor((startIndex + endIndex) / 2) |
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
| function factorial(){ | |
| const cache = {}; // create closure | |
| return function factMemoized(n) { | |
| if(n < 2) { | |
| return 1; | |
| } | |
| if(cache[n]) { | |
| console.log('return from cache ' + cache[n]) | |
| return cache[n]; // return from cache | |
| }else { |