-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
6,883 additions
and
5,644 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
function deepCount(a){ | ||
let count = 0; | ||
for (let elem of a){ | ||
if(Array.isArray(elem)){ | ||
count += 1 | ||
count +=deepCount(elem); | ||
} else { | ||
count++; | ||
} | ||
|
||
} | ||
return count; | ||
} | ||
|
||
console.log(deepCount([[], 1, 2, 3])) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module buildTower | ||
|
||
go 1.22.6 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func BuildTower(floors int) []string { | ||
tower := make([]string, floors) | ||
|
||
for i := 0; i < floors; i++ { | ||
|
||
stars := 2*i + 1 | ||
spaces := floors - i - 1 | ||
|
||
line := "" | ||
|
||
for j := 0; j < spaces; j++ { | ||
line += " " | ||
} | ||
|
||
for j := 0; j < stars; j++ { | ||
line += "*" | ||
} | ||
|
||
for j := 0; j < spaces; j++ { | ||
line += " " | ||
} | ||
tower[i] = line | ||
} | ||
return tower | ||
} | ||
|
||
func main() { | ||
new := BuildTower(10) | ||
|
||
for _, row := range new { | ||
fmt.Println(row) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module camelcase | ||
|
||
go 1.22.6 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
func ToCamelCase(s string) string { | ||
if len(s) == 0 { | ||
return "" | ||
} | ||
result := strings.Builder{} | ||
var nextUpper bool | ||
result.WriteByte(s[0]) | ||
newS := s[1:] | ||
for _, v := range []byte(strings.TrimSpace(newS)) { | ||
if v == ' ' || v == '-' || v == '_' { | ||
nextUpper = true | ||
continue | ||
} | ||
if nextUpper { | ||
v = ToUpper(v) | ||
nextUpper = false | ||
} | ||
result.WriteByte(v) | ||
} | ||
return result.String() | ||
} | ||
|
||
func ToUpper(b byte) byte { | ||
if b >= 'a' && b <= 'z' { | ||
return b - 'a' + 'A' | ||
} | ||
return b | ||
} | ||
|
||
func main() { | ||
var str string | ||
fmt.Scan(&str) | ||
res := ToCamelCase(str) | ||
fmt.Println(res) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module dublEnc | ||
|
||
go 1.22.6 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
func DuplicateEncode(word string) string { | ||
freqMap := make(map[rune]int) | ||
for _, char := range strings.ToLower(word) { | ||
freqMap[char]++ | ||
} | ||
var finalString strings.Builder | ||
for _, char := range strings.ToLower(word) { | ||
if freqMap[char] == 1 { | ||
finalString.WriteString("(") | ||
} else { | ||
finalString.WriteString(")") | ||
} | ||
} | ||
return finalString.String() | ||
} | ||
|
||
func main() { | ||
fmt.Println(DuplicateEncode("Hello")) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module findmissingletter | ||
|
||
go 1.22.6 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func FindMissingLetter(chars []rune) rune { | ||
var missingLetter int32 | ||
for i := 0; i < len(chars)-1; i++ { | ||
if chars[i+1]-chars[i] != 1 { | ||
missingLetter = chars[i+1] - 1 | ||
} | ||
} | ||
return missingLetter | ||
} | ||
|
||
func main() { | ||
slice := []rune{'a', 'b', 'c', 'e'} | ||
fmt.Print(FindMissingLetter(slice)) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package main | ||
|
||
func merge(arr1, arr2 []interface{}) []interface{} { | ||
var result []interface{} | ||
length1 := len(arr1) | ||
length2 := len(arr2) | ||
maxLength := length1 | ||
if length2 > length1 { | ||
maxLength = length2 | ||
} | ||
|
||
for i := 0; i < maxLength; i++ { | ||
if i < length1 { | ||
result = append(result, arr1[i]) | ||
} | ||
if i < length2 { | ||
result = append(result, arr2[i]) | ||
} | ||
} | ||
return result | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
function mergeArrays(arr1, arr2) { | ||
let result = []; | ||
let maxLength = Math.max(arr1.length, arr2.length); | ||
|
||
for (let i = 0; i < maxLength; i++) { | ||
if (i < arr1.length) { | ||
result.push(arr1[i]); | ||
} | ||
if (i < arr2.length) { | ||
result.push(arr2[i]); | ||
} | ||
} | ||
return result; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package main | ||
|
||
func MoveZeros(arr []int) []int { | ||
nonZero := []int{} | ||
countZero := 0 | ||
|
||
for _, num := range arr { | ||
if num != 0 { | ||
nonZero = append(nonZero, num) | ||
} else { | ||
countZero++ | ||
} | ||
} | ||
|
||
for i := 0; i < countZero; i++ { | ||
nonZero = append(nonZero, 0) | ||
} | ||
|
||
return nonZero | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module rootdigit | ||
|
||
go 1.22.6 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func DigitalRoot(n int) int { | ||
for n > 9 { | ||
n = sumDigits(n) | ||
} | ||
return n | ||
} | ||
|
||
func sumDigits(n int) int { | ||
var sum int | ||
for n > 0 { | ||
sum += n % 10 | ||
n = n / 10 | ||
} | ||
return sum | ||
} | ||
|
||
func main() { | ||
num := DigitalRoot(12345) | ||
fmt.Print(num) | ||
} |
Oops, something went wrong.