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
func twoSum(nums []int, target int) []int { | |
m := make(map[int]int) | |
for i := 0; i < len(nums); i++ { | |
curr := nums[i] | |
diff := target - curr | |
if _, ok := m[diff]; ok { | |
return []int{m[diff], 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
package main | |
import ( | |
"fmt" | |
"math" | |
) | |
func Sqrt(x float64) (float64, int) { | |
z := x/2 | |
prev := 0.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
const strictEquals = (a,b) => (Object.is(a,b) | |
? !Object.is(a, NaN) | |
: (Object.is(a, 0) && Object.is(b, -0)) || (Object.is(a, -0) && Object.is(b, 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
function palindrome(str) { | |
/* steps: | |
remove punctuation, spaces symbols | |
turn everything into lowercase | |
check if string inverted === str | |
*/ | |
let regexRemove = /[,.'"?!@#$%^&*()_-\s]/g | |
str = str.replace(regexRemove,"").toLowerCase() | |
// now we have a clean string | |
let newThing = [] |
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
let findLongestWordLength = (str) => { | |
let splitRegex = /[a-zA-z]+/gi | |
let longest = 0; | |
let words = str.match(splitRegex); | |
for(let i = 0; i < words.length; i++ ) { | |
let currWordLen = words[i].length; | |
if(currWordLen > longest) { | |
longest = currWordLen; | |
} | |
} |
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
let fact = (num) => (num <= 0 ? 1 : num * fact(num - 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
// this is my solution to the following freeCodeCamp challenge: | |
// freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-algorithm-scripting/reverse-a-string | |
let reverseString = (str) => { | |
let reversedArray = []; | |
let finalString = ""; | |
for(let i = 0; i < str.length; i++){ | |
reversedArray.unshift(str[i]); | |
} | |
for(let j = 0; j < reversedArray.length; j++){ | |
finalString += reversedArray[j] |
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 updateRecords(records, id, prop, value) { | |
var record = records[id]; | |
if(prop !== "tracks" && value !== "") { | |
record[prop] = value; | |
} else if (value === ""){ | |
delete record[prop]; | |
} else if (prop == "tracks") { | |
if(record.hasOwnProperty("tracks") === false) { | |
record["tracks"] = []; | |
record["tracks"].push(value); |