Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- One liner
- var fizzbuzz = [ -- create named set fizzbuzz
- [1..100] -- create set of integers 1 through 100 (exclusively)
- .map(Integer::toString) -- map each entry to the string of the integer
- .replace( -- replace duplicate entries of set
- [1..100|3] -- create set of integers 1 through 100 (exclusively) incrementing by 3
- .map("fizz") -- map each entry to the string "fizz"
- .join( -- join (set, function)
- [1..100|5] -- create set of integers 1 through 100 (exclusively) incrementing by 5
- .map("buzz"), -- map each entry to the string "buzz"
- (entry1, entry2) -> entry1 + entry2 -- lambda takes two two parameters and returns single object
- ) -- join complete for fizz and buzz sets, sent to replace function
- ) -- replace complete
- ]; -- assignment complete
- -- Better Visibility.
- var fizzbuzz = [];
- var temp = [1..100].map(Integer::toString);
- var fizz = [1..100|3].map("fizz");
- var buzz = [1..100|5].map("buzz");
- func rpl = (e1, e2) -> e2;
- func acc = (e1, e2) -> e1 + e2;
- var fzbz = fizz.join(buzz, acc);
- fizzbuzz = temp.join(fzbz, rpl);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement