Skip to content

Commit

Permalink
codewars+mathFunc+Classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Krovaldo committed Oct 8, 2024
1 parent 58b5956 commit 969aabc
Show file tree
Hide file tree
Showing 25 changed files with 6,883 additions and 5,644 deletions.
15 changes: 15 additions & 0 deletions codewars/Array Deep Count/main.js
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]))
3 changes: 3 additions & 0 deletions codewars/Build Tower/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module buildTower

go 1.22.6
37 changes: 37 additions & 0 deletions codewars/Build Tower/main.go
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)
}
}
3 changes: 3 additions & 0 deletions codewars/Convert string to camel case/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module camelcase

go 1.22.6
42 changes: 42 additions & 0 deletions codewars/Convert string to camel case/main.go
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)
}
3 changes: 3 additions & 0 deletions codewars/Duplicate Encoder/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module dublEnc

go 1.22.6
26 changes: 26 additions & 0 deletions codewars/Duplicate Encoder/main.go
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"))
}
3 changes: 3 additions & 0 deletions codewars/Find the missing letter/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module findmissingletter

go 1.22.6
18 changes: 18 additions & 0 deletions codewars/Find the missing letter/main.go
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))
}
24 changes: 24 additions & 0 deletions codewars/Merge two arrays/main.go
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() {
}
14 changes: 14 additions & 0 deletions codewars/Merge two arrays/mainJS.js
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;
}
20 changes: 20 additions & 0 deletions codewars/Moving Zeros To The End/main.go
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
}
3 changes: 3 additions & 0 deletions codewars/Sum of Digits - Digital Root/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module rootdigit

go 1.22.6
24 changes: 24 additions & 0 deletions codewars/Sum of Digits - Digital Root/main.go
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)
}
Loading

0 comments on commit 969aabc

Please sign in to comment.