HexCardsClient/utils/vec.wren
2021-05-23 16:20:37 +02:00

42 lines
No EOL
1,009 B
Text

class Vec{
static add(first: List, second: List){
var count = first.count.min(second.count)
var result = []
for(i in 0...count){
result.add(first[i] + second[i])
}
return result
}
static sub(first: List, second: List){
var count = first.count.min(second.count)
var result = []
for(i in 0...count){
result.add(first[i] - second[i])
}
return result
}
static mul(first: List, second: Any){
if(first is Num && second is List) return mul(second, first)
var secondNum = second is Num
var count = secondNum ? first.count : (first.count.min(second.count))
var result = []
for(i in 0...count){
result.add(first[i] * (secondNum?second:second[i]))
}
return result
}
static div(first: List, second: Any){
var secondNum = second is Num
var count = secondNum ? first.count : first.count.min(second.count)
var result = []
for(i in 0...count){
result.add(first[i] / secondNum?second:second[i])
}
return result
}
}