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
package main | |
import ( | |
"fmt" | |
"strings" | |
s "strings" | |
) | |
func main() { |
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
package main | |
import "fmt" | |
type UserProfile struct { | |
username string | |
email string | |
age int | |
avatarURL string | |
} |
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 insertionSort(arr) { | |
for (let i =1; i < arr.length; i++) { | |
let currentVal = arr[i]; | |
let j; | |
for (j=i-1; j>=0 && arr[j] > currentVal;j--) { | |
arr[j+1] = arr[j]; | |
} | |
arr[j+1] = currentVal; | |
console.log(arr); | |
} |
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 selectionSort(arr) { | |
for (let i=0; i < arr.length; i++) { | |
let lowest = i; | |
for(let j = i+1; j < arr.length; j++) { | |
if (arr[j] < arr[lowest]) { | |
lowest = j; | |
} | |
} | |
if (i !== lowest) { | |
let temp = arr[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
//naive solution | |
function bubbleSort(arr) { | |
for (let i=0; i< arr.length; i++) { | |
for (let j=0; j< arr.length; j++) { | |
console.log(arr, arr[j], arr[j+1]); | |
if (arr[j] > arr[j+1]) { | |
//swap | |
let temp = arr[j]; | |
arr[j] = arr[j+1]; | |
arr[j+1] = temp; |
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 naiveSearch(long, short) { | |
let count = 0; | |
for (let i = 0; i<long.length; i++) { | |
for(let j=0; j<short.length; j++) { | |
if (short[j] !== long[i+j]) { | |
console.log('break'); | |
break; | |
} | |
if (j === short.length -1) { | |
count++; |
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 binarySearch(ar, elem) { | |
let start = 0; | |
let end = ar.length -1; | |
let mid = Math.floor((start + end) / 2); | |
while(ar[mid] !== elem && start < end ) { | |
if (elem < ar[mid]) end = mid - 1; | |
else start = mid + 1; | |
mid = Math.floor((start + end) / 2); | |
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
//helper/controller.js | |
var pathModule = require('path'); | |
var fs = require('fs'); | |
exports.pathLocation = function () { | |
var basePath = pathModule.resolve(__dirname,'../controllers'); | |
var controllers = {}; |
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
github-create(){ | |
repo_name=$1 | |
dir_name=`basename $(pwd)` | |
invalid_credentials="" | |
if ["$repo_name" = ""]; then | |
echo "Repo Name (hit return to use) '$dir_name' ?" | |
read repo_name | |
fi |
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
def anagrams(n) | |
text = File.open('words.txt').read | |
candidates = [] | |
text.each_line do |line| | |
if (line.length - 1) == n.length | |
candidates << line.gsub("\n",'') | |
end | |
end |