Kata of the Day #12

Lost without a map

kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
kata
Kata of the Day #12

Given an array of integers, return a new array with each value doubled.

TypeScript


function maps(x: number[]): number[] {
    return x.map(y => y * 2);
}

console.log(maps([1,2]);

Go


package main

import "fmt"

func maps(x []int) []int {
	for i, v := range x {
		x[i] = v * 2
	}
	return x
}

func main() {
	var arr []int = []int{1, 2}
	fmt.Println(maps(arr))
}

Python


def maps(x):
    return list(map(lambda y: y * 2, x))


print(maps([1,2]))

PHP


function maps($x) {
    return array_map(function($y) {
        return $y * 2;
    }, $x);
}

echo maps([1,2]);

Go to Kata
ByJulie Kohl

Need some help?

Want 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
budget
budget
budget
budget
budget
budget
budget
budget
budget
budget

Subscribe to our newsletter

subscribe
subscribe
subscribe
subscribe
subscribe
subscribe
subscribe
subscribe
subscribe
subscribe