Skip to content

Instantly share code, notes, and snippets.

@RikiyaOta
Created October 22, 2018 03:59
Show Gist options
  • Save RikiyaOta/7b28ae085664196c71b6e904b0f68947 to your computer and use it in GitHub Desktop.
Save RikiyaOta/7b28ae085664196c71b6e904b0f68947 to your computer and use it in GitHub Desktop.
[javascript]reduceっぽい関数を書いてみる
function sumOfArray(arr, sum = 0){
if(arr.lenth === 0) return sum;
else{
const [first, ...rest] = arr;
return sumOfArray(rest, first + sum);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment