Created
March 2, 2017 18:49
-
-
Save masotime/3f90b1215595edd960386a8969f79f55 to your computer and use it in GitHub Desktop.
Using bash to implement recursion-based reduce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function testRecurse { | |
ONE=${1:0} | |
TWO=("${@:1}") | |
if [[ $# -eq 1 ]]; then | |
echo Final answer $ONE | |
else | |
echo \|${TWO[1]}\| | |
let ACC=ONE+TWO[1] | |
ARR=("${TWO[@]:2}") | |
echo recursion $ACC - $ARR | |
testRecurse $ACC ${ARR[@]} | |
fi | |
} | |
testRecurse | |
testRecurse 10 | |
testRecurse 10 1 2 3 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment