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
// Can be used as foundation for algo questions which ask to split number into digits and manipulate it in some way afterward | |
function numberToSumOfDigits(num) { | |
let totalSum = 0; | |
while(num > 0){ | |
const digit = num %10 | |
num = Math.floor(num/10); | |
totalSum += digit | |
} | |
return totalSum |
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} s | |
* @return {number} | |
*/ | |
var romanToInt = function(s) { | |
let result = 0 | |
const conversion = { | |
"I": 1, | |
"V": 5, | |
"X": 10, |
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
// Node definition | |
function TreeNode(val) { | |
this.val = val; | |
this.left = this.right = null; | |
} | |
// Assemle a tree | |
const left = new TreeNode(2) | |
const right = new TreeNode(2) | |
const rightRight = new TreeNode(3) |
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
type Review { | |
body: String | |
author: User @provides(fields: "username") | |
product: Product | |
} | |
extend type User @key(fields: "id") { | |
id: ID! @external | |
reviews: [Review] | |
} |
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
// Code source https://btholt.github.io/four-semesters-of-cs-part-two/pathfinding | |
const NO_ONE = 0; | |
const BY_A = 1; | |
const BY_B = 2; | |
const processSearchIteration = ()=>{ | |
const aNeighbors = aQueue.reduce((acc, neighbor)=>{ | |
return acc.concat(getNeighbors(visited, neighbor.x, neighbor.y)) | |
}, []) |
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
// Code originnaly belong to Front End Masters course | |
// 4 Semesters of CS in 5 Hours part II | |
//https://btholt.github.io/four-semesters-of-cs-part-two/ | |
const CITY_NAMES = [ | |
"New York", | |
"Los Angeles", | |
"Chicago", | |
"Houston", | |
"Philadelphia", |
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 doughnuts_box | |
import ( | |
"fmt" | |
) | |
type doughnutsBox struct { | |
capacity int | |
doughnuts []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 doughnuts_box | |
import ( | |
"testing" | |
"github.com/stretchr/testify/assert" | |
"github.com/stretchr/testify/require" | |
) | |
func TestPackDoughnutsBoxTableTests(t *testing.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
package doughnuts_box | |
import ( | |
"testing" | |
"github.com/stretchr/testify/assert" | |
"github.com/stretchr/testify/require" | |
) | |
func TestPackDoughnutsBoxSubtests(t *testing.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
package main | |
import "fmt" | |
type person struct { | |
name string | |
} | |
// the * denotes(indicate) a pointer to a value of the type that follows the * | |
// *person the func return pointer |