Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Double number in list (recursive)
function doubleList(listOfNumbers: number[]): number[] {
if(!listOfNumbers.length) return [];
return [
...doubleList(listOfNumbers.slice(1, listOfNumbers.length))
function double(n: number) {
return n * 2;
console.log(doubleList([1,2,3,4,5])) // [2,4,6,8,10]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment