Skip to content

Instantly share code, notes, and snippets.

View spcbfr's full-sized avatar
💙
Learning Go!

Yusuf Bouzekri spcbfr

💙
Learning Go!
View GitHub Profile
@spcbfr
spcbfr / twoSum.go
Created March 1, 2024 05:54
Two Sum solved in golang with hashmaps
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}
}
@spcbfr
spcbfr / sqrt.go
Created February 24, 2024 20:16
Square root approximation algorithm in Go
package main
import (
"fmt"
"math"
)
func Sqrt(x float64) (float64, int) {
z := x/2
prev := 0.0
@spcbfr
spcbfr / scrictEquals.js
Created September 27, 2023 12:45
scriptEquals
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)))
}
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 = []
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;
}
}
let fact = (num) => (num <= 0 ? 1 : num * fact(num - 1))
// 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]
@spcbfr
spcbfr / FreeCodeCamp_record_collection_sol.js
Created July 10, 2021 11:13
The solution to the free code camp challenge called "Record Collection", from the JavaScript Algorithms and Data Structures Course
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);
@spcbfr
spcbfr / suckless-dmenu.h
Last active July 6, 2021 09:03
Suckless Spaceduck Port
// add this to your dmenu config.h
static const char *colors[SchemeLast][2] = {
/* fg bg */
[SchemeNorm] = { "#ecf0c1", "#0f111b" },
[SchemeSel] = { "#0f111b", "#f2b45c" },
[SchemeOut] = { "#000000", "#5ccc96" },
};