Array diff
Your goal in this kata is to implement a difference function, which subtracts one list from another and returns the result.
function arrayDiff(a: number[], b: number[]): number[] {
return a.filter(e => !b.includes(e));
}
console.log(arrayDiff([3, 4], [3]));
package main
import (
"fmt"
)
func arrayDiff(a []int, b []int) []int {
diff := []int{}
for _, e := range a {
if !contains(b, e) {
diff = append(diff, e)
}
}
return diff
}
func contains(arr []int, val int) bool {
for _, el := range arr {
if el == val {
return true
}
}
return false
}
func main() {
fmt.Println(arrayDiff([]int{3, 4}, []int{3}))
}
def array_diff(a, b):
return [e for e in a if e not in b]
print(array_diff([3, 4], [3]))
function arrayDiff($a, $b) {
return array_filter($a, function($e) use ($b) {
return !in_array($e, $b);
});
}
echo print_r(arrayDiff([3, 4], [3]));
Go to KataWant us to give you some help with your business? No problem, here's a video on who we can help, and how, along with our calendar so you can book in a call to discuss us working together.
Let's see