vincentlowe icon

using reduce() (DWE)

vincentlowe | PRO | 03/31/22 05:14:45 PM UTC | 0 ⭐ | 197 👁️ | Never ⏰ | []
text |

440 B

|

None

|

0 👍

/

0 👎

var a1 = 2 to 5
 var aos = [
	"bob",
	"carol",
	"ted",
	"alice"
]
 ---
{
	lastElement: a1 reduce (e,a) -> e,
	firstElement: a1 reduce (e,a) -> a,
	initializedAccumulator: a1 reduce (e,a=0) -> a,
	sumElements: a1 reduce (e,a) -> a + e,
	concatElements: a1 reduce (e,a="") -> a ++ e,
	stackElements: a1 reduce (e,a=[]) -> e >> a,
	concatStrings: aos reduce (e,a) -> a ++ "," ++ e,
	reverseConcat: aos reduce (e,a) -> e ++ "," ++ a,
}

Comments