SlideShare a Scribd company logo
_
Underscore.js
provides 80-odd functions that support both the usual functional suspects


Andries Nieuwenhuize - Quadrant Software B.V. - 12 maart 2013
Inhoud
          Basic
             Filter
             Projectie
             Fold
          Advanced
             Zip
             Distinct
             Extend
          Live
             Chaining
             Sudoku
             Column-row invert
             Birthday paradox
_.filter([1, 2, 3], function(num) {

Basics                      return num % 2 == 1;
                      });
                      -> [1, 3]
         Filter
         Projection
                      _.reject([1, 2, 3], function(num) {
         Fold               return num % 2 == 1;
                      });
                      -> [2]


                      _.without([1, 2, 3, 4, 5, 6, 7, 8, 9], 8, 1);
                      -> [2, 3, 4, 5, 6, 7, 9]


                      _.where(persons, { age : 22 });
                      -> [{ name: “Fred”, age : 22, userId: 001 },
                            { name: “Hans”, age : 22, userId: 002 }]
[{ name: “Fred”, age : 22, userId: 001 },

Basics                { name: “Hans”, age : 22, userId: 002 }
                      { name: “Karel”, age : 67, userId: 006 }]

         Filter
                      _.map([1, 2, 3], function(num) {
         Projection         return num * num;
         Fold         });
                      -> [1, 4, 9]


                      _.pluck(persons, “name” );
                      -> [ “Fred”, “Hans”, “Karel” ]


                      _.pick(persons[0], “name”, “age” );
                      -> { name: “Fred”, age : 22 }


                      _.omit(persons[0], “name”, “age” );
                      -> { userId: 001 }
Basics                _.reduce([1, 2, 3], function(memo, num) {
                          return memo * num;
         Filter       }, 1);

         Projection   -> 9

         Fold
                      _.reduce([1, 2, 3], function(memo, num) {
                          return memo + num;
                      }, 0);
                      -> 6


                      _.max([1, 2, 3]);
                      -> 3
Advanced


           Zip
           Distinct e.d.   _.zip(['-', '-', '-'], ['+', '+', '+'])
           Extend          -> ['-', '+', '-', '+', '-', '+']


                           _.object(['a', 'b', 'c'], [1, 2, 3]);
                           -> {'a' :   1, 'b' : 2, 'c' : 3 }
Advanced
                           _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]);
           Zip             -> [1, 2, 3, 101, 10]

           Distinct e.d.
                           _.intersection(
           Extend
                                 [1, 2, 3], [101, 2, 1, 10], [2, 1]);
                           -> [1, 2]


                           _.difference([1, 2, 3, 4, 5], [5, 2, 10]);
                           -> [1, 3, 4]


                           _.uniq([1, 2, 1, 3, 1, 4]);
                           -> [1, 2, 3, 4]
var sum = function(lst) {
Advanced                         return _.reduce(lst, function(memo, num) {
                                      return memo + num;
                                 } , 0);
           Zip
                           };
           Distinct e.d.   > sum([1, 2, 3]);
           Extend
                           _.mixin({
                                 sum : function(lst) {
                                      return _.reduce(lst, function(memo, num) {
                                           return memo + num;
                                      } , 0);
                                 },
                                 avg : function(lst) {
                                      return _.sum(lst) / lst.length;
                                 }
                           });


                           > _.avg([1, 2, 3]);
Live
                    var persons = [
                       { name: "Piet",
Chaining
                            age: 22 },
Sudoku                 { name: "Kees",
Column-row invert           age : 54 },

Birthday paradox       { name: "Sarah",
                            age : 18 }
                       ];


                    _.chain(persons)
                       .pluck("age")
                       .avg()
                       .value();
                    -> 31,333333333333333332
Live

Chaining
Sudoku
Column-row invert
Birthday paradox

                    // First step in Sudoku-algorithm (reduce)
                    _.chain([1, 2, 3, 4, 5, 6, 7, 8, 9])
                        .without(7, 4, 3, 9)   // block
                        .without(3, 9)         // row
                        .without(7, 5, 9, 3)   // column
                        .value();
                    -> [1,2,6,8]
// Medieval is Evil!
                    var invert = function(columns) {
                      var res = [];
  Live                for(var i = 0; i< columns.length; i++) {
                         var row = columns[i];
Chaining                   for (var j = 0; j < row.length; j++) {
                              if(! res[j])
Sudoku                           res[j] = [];
Column-row invert
                               res[j][i] = row[j];
Birthday paradox           }
                         }
                         return res;
                    };
                    // Just zip-it
                    _.zip(['moe', 'larry', 'curly'],
                               [30, 40, 50],
                               [true, false, false]);


                    -> [moe,30,true],
                          [larry,40,false],
                          [curly,50,false]
var min = 1,     // 1th January
                                                           max = 365; // 31 December

  Live
                                                      // produce birthdays
                                                      var getNextBirthday = function() {
Chaining                                                   return _.random(min, max);

Sudoku                                                };

Column-row invert                                     // check for double dates
Birthday paradox                                      var isMatchFound = function(lst) {
                                                           return lst.length > _.uniq(lst).length;
                                                      };


    // Birthday paradox (BP) - probability theorie    // loop until first hit
    // Some have the same brithday:                   var getFirstHit = function() {

    // 100% - 366 people needed. -> 365 in 'normal'        var loop = function(lst) {
    year                                                        lst.push(getNextBirthday());

    // BP -> 99% 57 people                                      if (IsMatchFound(lst)) {
                                                                    return lst.length; // attempts
    // BP -> 50% 23 people
                                                                }
                                                                else { return loop(lst); }
                                                           };
                                                           return loop([]); // start
                                                      };

More Related Content

What's hot

Couchdb
CouchdbCouchdb
Couchdb
Brian Smith
 
MongoDB With Style
MongoDB With StyleMongoDB With Style
MongoDB With Style
Gabriele Lana
 
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rick Copeland
 
Contando uma história com O.O.
Contando uma história com O.O.Contando uma história com O.O.
Contando uma história com O.O.Vagner Zampieri
 
Thoughts on MongoDB Analytics
Thoughts on MongoDB AnalyticsThoughts on MongoDB Analytics
Thoughts on MongoDB Analytics
rogerbodamer
 
Magicke metody v Pythonu
Magicke metody v PythonuMagicke metody v Pythonu
Magicke metody v PythonuJirka Vejrazka
 
Webinar: Replication and Replica Sets
Webinar: Replication and Replica SetsWebinar: Replication and Replica Sets
Webinar: Replication and Replica Sets
MongoDB
 
Python chapter 2
Python chapter 2Python chapter 2
Python chapter 2Raghu nath
 
python chapter 1
python chapter 1python chapter 1
python chapter 1Raghu nath
 
A Taste of Python - Devdays Toronto 2009
A Taste of Python - Devdays Toronto 2009A Taste of Python - Devdays Toronto 2009
A Taste of Python - Devdays Toronto 2009
Jordan Baker
 
Knockout
KnockoutKnockout
Knockout
LearningTech
 
The Ring programming language version 1.5.3 book - Part 62 of 184
The Ring programming language version 1.5.3 book - Part 62 of 184The Ring programming language version 1.5.3 book - Part 62 of 184
The Ring programming language version 1.5.3 book - Part 62 of 184
Mahmoud Samir Fayed
 
The Ring programming language version 1.3 book - Part 42 of 88
The Ring programming language version 1.3 book - Part 42 of 88The Ring programming language version 1.3 book - Part 42 of 88
The Ring programming language version 1.3 book - Part 42 of 88
Mahmoud Samir Fayed
 
30 分鐘學會實作 Python Feature Selection
30 分鐘學會實作 Python Feature Selection30 分鐘學會實作 Python Feature Selection
30 分鐘學會實作 Python Feature Selection
James Huang
 
C# 3.5 Features
C# 3.5 FeaturesC# 3.5 Features
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)Night Sailer
 
Andreas Roth - GraphQL erfolgreich im Backend einsetzen
Andreas Roth - GraphQL erfolgreich im Backend einsetzenAndreas Roth - GraphQL erfolgreich im Backend einsetzen
Andreas Roth - GraphQL erfolgreich im Backend einsetzen
DevDay Dresden
 
Data visualization with Python and SVG
Data visualization with Python and SVGData visualization with Python and SVG
Data visualization with Python and SVG
Sukjun Kim
 

What's hot (20)

Couchdb
CouchdbCouchdb
Couchdb
 
MongoDB With Style
MongoDB With StyleMongoDB With Style
MongoDB With Style
 
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
 
Contando uma história com O.O.
Contando uma história com O.O.Contando uma história com O.O.
Contando uma história com O.O.
 
2013 2-5
2013 2-52013 2-5
2013 2-5
 
Thoughts on MongoDB Analytics
Thoughts on MongoDB AnalyticsThoughts on MongoDB Analytics
Thoughts on MongoDB Analytics
 
Magicke metody v Pythonu
Magicke metody v PythonuMagicke metody v Pythonu
Magicke metody v Pythonu
 
Webinar: Replication and Replica Sets
Webinar: Replication and Replica SetsWebinar: Replication and Replica Sets
Webinar: Replication and Replica Sets
 
Python chapter 2
Python chapter 2Python chapter 2
Python chapter 2
 
python chapter 1
python chapter 1python chapter 1
python chapter 1
 
A Taste of Python - Devdays Toronto 2009
A Taste of Python - Devdays Toronto 2009A Taste of Python - Devdays Toronto 2009
A Taste of Python - Devdays Toronto 2009
 
Knockout
KnockoutKnockout
Knockout
 
The Ring programming language version 1.5.3 book - Part 62 of 184
The Ring programming language version 1.5.3 book - Part 62 of 184The Ring programming language version 1.5.3 book - Part 62 of 184
The Ring programming language version 1.5.3 book - Part 62 of 184
 
The Ring programming language version 1.3 book - Part 42 of 88
The Ring programming language version 1.3 book - Part 42 of 88The Ring programming language version 1.3 book - Part 42 of 88
The Ring programming language version 1.3 book - Part 42 of 88
 
30 分鐘學會實作 Python Feature Selection
30 分鐘學會實作 Python Feature Selection30 分鐘學會實作 Python Feature Selection
30 分鐘學會實作 Python Feature Selection
 
C# 3.5 Features
C# 3.5 FeaturesC# 3.5 Features
C# 3.5 Features
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)
 
Andreas Roth - GraphQL erfolgreich im Backend einsetzen
Andreas Roth - GraphQL erfolgreich im Backend einsetzenAndreas Roth - GraphQL erfolgreich im Backend einsetzen
Andreas Roth - GraphQL erfolgreich im Backend einsetzen
 
Data visualization with Python and SVG
Data visualization with Python and SVGData visualization with Python and SVG
Data visualization with Python and SVG
 
Notes for gm
Notes for gmNotes for gm
Notes for gm
 

Viewers also liked

Rubricas de exposición lecturas
Rubricas de exposición lecturasRubricas de exposición lecturas
Rubricas de exposición lecturas
Shirley Osuna
 
Enterprise social networking thesis niels peetermans
Enterprise social networking   thesis niels peetermansEnterprise social networking   thesis niels peetermans
Enterprise social networking thesis niels peetermans
Niels Peetermans
 
Trabalho de redação, o amor
Trabalho de redação, o amorTrabalho de redação, o amor
Trabalho de redação, o amor
Yuri Raphael
 
Limbic system and psychiatric disorders
Limbic system and psychiatric disordersLimbic system and psychiatric disorders
Limbic system and psychiatric disorders
Karrar Husain
 
Sleep disorders and psychiatry
Sleep disorders and psychiatrySleep disorders and psychiatry
Sleep disorders and psychiatry
Karrar Husain
 

Viewers also liked (8)

Rubricas de exposición lecturas
Rubricas de exposición lecturasRubricas de exposición lecturas
Rubricas de exposición lecturas
 
Enterprise social networking thesis niels peetermans
Enterprise social networking   thesis niels peetermansEnterprise social networking   thesis niels peetermans
Enterprise social networking thesis niels peetermans
 
Age
AgeAge
Age
 
Power mery tasques
Power mery tasquesPower mery tasques
Power mery tasques
 
Trabalho de redação, o amor
Trabalho de redação, o amorTrabalho de redação, o amor
Trabalho de redação, o amor
 
Consumer beauty preferences
Consumer beauty preferencesConsumer beauty preferences
Consumer beauty preferences
 
Limbic system and psychiatric disorders
Limbic system and psychiatric disordersLimbic system and psychiatric disorders
Limbic system and psychiatric disorders
 
Sleep disorders and psychiatry
Sleep disorders and psychiatrySleep disorders and psychiatry
Sleep disorders and psychiatry
 

Similar to Underscore

Ken20150417
Ken20150417Ken20150417
Ken20150417
LearningTech
 
Coscup2021-rust-toturial
Coscup2021-rust-toturialCoscup2021-rust-toturial
Coscup2021-rust-toturial
Wayne Tsai
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1
Ke Wei Louis
 
Lập trình Python cơ bản
Lập trình Python cơ bảnLập trình Python cơ bản
Lập trình Python cơ bản
Nguyen Thi Lan Phuong
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語
ikdysfm
 
Useful javascript
Useful javascriptUseful javascript
Useful javascriptLei Kang
 
Groovy collection api
Groovy collection apiGroovy collection api
Groovy collection api
trygvea
 
Thinking Functionally In Ruby
Thinking Functionally In RubyThinking Functionally In Ruby
Thinking Functionally In RubyRoss Lawley
 
Chapter 3 Built-in Data Structures, Functions, and Files .pptx
Chapter 3 Built-in Data Structures, Functions, and Files .pptxChapter 3 Built-in Data Structures, Functions, and Files .pptx
Chapter 3 Built-in Data Structures, Functions, and Files .pptx
SovannDoeur
 
Extending Operators in Perl with Operator::Util
Extending Operators in Perl with Operator::UtilExtending Operators in Perl with Operator::Util
Extending Operators in Perl with Operator::Util
Nova Patch
 
Python basic
Python basic Python basic
Python basic
sewoo lee
 
Modern Application Foundations: Underscore and Twitter Bootstrap
Modern Application Foundations: Underscore and Twitter BootstrapModern Application Foundations: Underscore and Twitter Bootstrap
Modern Application Foundations: Underscore and Twitter Bootstrap
Howard Lewis Ship
 
Python 내장 함수
Python 내장 함수Python 내장 함수
Python 내장 함수
용 최
 
Javascript
JavascriptJavascript
Javascript
Vlad Ifrim
 
A quick introduction to R
A quick introduction to RA quick introduction to R
A quick introduction to R
Angshuman Saha
 
7li7w devcon5
7li7w devcon57li7w devcon5
7li7w devcon5
Kerry Buckley
 
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov VyacheslavSeminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov VyacheslavVyacheslav Arbuzov
 
Pre-Bootcamp introduction to Elixir
Pre-Bootcamp introduction to ElixirPre-Bootcamp introduction to Elixir
Pre-Bootcamp introduction to Elixir
Paweł Dawczak
 
Programming for Artists and Designers: Week 2
Programming for Artists and Designers: Week 2Programming for Artists and Designers: Week 2
Programming for Artists and Designers: Week 2
Tinker London
 
Programming for Artists and Designers: Week 2
Programming for Artists and Designers: Week 2Programming for Artists and Designers: Week 2
Programming for Artists and Designers: Week 2
Tinker
 

Similar to Underscore (20)

Ken20150417
Ken20150417Ken20150417
Ken20150417
 
Coscup2021-rust-toturial
Coscup2021-rust-toturialCoscup2021-rust-toturial
Coscup2021-rust-toturial
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1
 
Lập trình Python cơ bản
Lập trình Python cơ bảnLập trình Python cơ bản
Lập trình Python cơ bản
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語
 
Useful javascript
Useful javascriptUseful javascript
Useful javascript
 
Groovy collection api
Groovy collection apiGroovy collection api
Groovy collection api
 
Thinking Functionally In Ruby
Thinking Functionally In RubyThinking Functionally In Ruby
Thinking Functionally In Ruby
 
Chapter 3 Built-in Data Structures, Functions, and Files .pptx
Chapter 3 Built-in Data Structures, Functions, and Files .pptxChapter 3 Built-in Data Structures, Functions, and Files .pptx
Chapter 3 Built-in Data Structures, Functions, and Files .pptx
 
Extending Operators in Perl with Operator::Util
Extending Operators in Perl with Operator::UtilExtending Operators in Perl with Operator::Util
Extending Operators in Perl with Operator::Util
 
Python basic
Python basic Python basic
Python basic
 
Modern Application Foundations: Underscore and Twitter Bootstrap
Modern Application Foundations: Underscore and Twitter BootstrapModern Application Foundations: Underscore and Twitter Bootstrap
Modern Application Foundations: Underscore and Twitter Bootstrap
 
Python 내장 함수
Python 내장 함수Python 내장 함수
Python 내장 함수
 
Javascript
JavascriptJavascript
Javascript
 
A quick introduction to R
A quick introduction to RA quick introduction to R
A quick introduction to R
 
7li7w devcon5
7li7w devcon57li7w devcon5
7li7w devcon5
 
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov VyacheslavSeminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
 
Pre-Bootcamp introduction to Elixir
Pre-Bootcamp introduction to ElixirPre-Bootcamp introduction to Elixir
Pre-Bootcamp introduction to Elixir
 
Programming for Artists and Designers: Week 2
Programming for Artists and Designers: Week 2Programming for Artists and Designers: Week 2
Programming for Artists and Designers: Week 2
 
Programming for Artists and Designers: Week 2
Programming for Artists and Designers: Week 2Programming for Artists and Designers: Week 2
Programming for Artists and Designers: Week 2
 

More from Andries Nieuwenhuize

Builder
BuilderBuilder
Strategy
StrategyStrategy
Linq inside out
Linq inside outLinq inside out
Linq inside out
Andries Nieuwenhuize
 
FSharp @ Quadrant
FSharp @ QuadrantFSharp @ Quadrant
FSharp @ Quadrant
Andries Nieuwenhuize
 
Presentatie
PresentatiePresentatie

More from Andries Nieuwenhuize (6)

Builder
BuilderBuilder
Builder
 
Strategy
StrategyStrategy
Strategy
 
Internationalization quadrant
Internationalization quadrantInternationalization quadrant
Internationalization quadrant
 
Linq inside out
Linq inside outLinq inside out
Linq inside out
 
FSharp @ Quadrant
FSharp @ QuadrantFSharp @ Quadrant
FSharp @ Quadrant
 
Presentatie
PresentatiePresentatie
Presentatie
 

Underscore

  • 1. _ Underscore.js provides 80-odd functions that support both the usual functional suspects Andries Nieuwenhuize - Quadrant Software B.V. - 12 maart 2013
  • 2. Inhoud  Basic  Filter  Projectie  Fold  Advanced  Zip  Distinct  Extend  Live  Chaining  Sudoku  Column-row invert  Birthday paradox
  • 3. _.filter([1, 2, 3], function(num) { Basics return num % 2 == 1; }); -> [1, 3] Filter Projection _.reject([1, 2, 3], function(num) { Fold return num % 2 == 1; }); -> [2] _.without([1, 2, 3, 4, 5, 6, 7, 8, 9], 8, 1); -> [2, 3, 4, 5, 6, 7, 9] _.where(persons, { age : 22 }); -> [{ name: “Fred”, age : 22, userId: 001 }, { name: “Hans”, age : 22, userId: 002 }]
  • 4. [{ name: “Fred”, age : 22, userId: 001 }, Basics { name: “Hans”, age : 22, userId: 002 } { name: “Karel”, age : 67, userId: 006 }] Filter _.map([1, 2, 3], function(num) { Projection return num * num; Fold }); -> [1, 4, 9] _.pluck(persons, “name” ); -> [ “Fred”, “Hans”, “Karel” ] _.pick(persons[0], “name”, “age” ); -> { name: “Fred”, age : 22 } _.omit(persons[0], “name”, “age” ); -> { userId: 001 }
  • 5. Basics _.reduce([1, 2, 3], function(memo, num) { return memo * num; Filter }, 1); Projection -> 9 Fold _.reduce([1, 2, 3], function(memo, num) { return memo + num; }, 0); -> 6 _.max([1, 2, 3]); -> 3
  • 6. Advanced Zip Distinct e.d. _.zip(['-', '-', '-'], ['+', '+', '+']) Extend -> ['-', '+', '-', '+', '-', '+'] _.object(['a', 'b', 'c'], [1, 2, 3]); -> {'a' : 1, 'b' : 2, 'c' : 3 }
  • 7. Advanced _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); Zip -> [1, 2, 3, 101, 10] Distinct e.d. _.intersection( Extend [1, 2, 3], [101, 2, 1, 10], [2, 1]); -> [1, 2] _.difference([1, 2, 3, 4, 5], [5, 2, 10]); -> [1, 3, 4] _.uniq([1, 2, 1, 3, 1, 4]); -> [1, 2, 3, 4]
  • 8. var sum = function(lst) { Advanced return _.reduce(lst, function(memo, num) { return memo + num; } , 0); Zip }; Distinct e.d. > sum([1, 2, 3]); Extend _.mixin({ sum : function(lst) { return _.reduce(lst, function(memo, num) { return memo + num; } , 0); }, avg : function(lst) { return _.sum(lst) / lst.length; } }); > _.avg([1, 2, 3]);
  • 9. Live var persons = [ { name: "Piet", Chaining age: 22 }, Sudoku { name: "Kees", Column-row invert age : 54 }, Birthday paradox { name: "Sarah", age : 18 } ]; _.chain(persons) .pluck("age") .avg() .value(); -> 31,333333333333333332
  • 10. Live Chaining Sudoku Column-row invert Birthday paradox // First step in Sudoku-algorithm (reduce) _.chain([1, 2, 3, 4, 5, 6, 7, 8, 9]) .without(7, 4, 3, 9) // block .without(3, 9) // row .without(7, 5, 9, 3) // column .value(); -> [1,2,6,8]
  • 11. // Medieval is Evil! var invert = function(columns) { var res = []; Live for(var i = 0; i< columns.length; i++) { var row = columns[i]; Chaining for (var j = 0; j < row.length; j++) { if(! res[j]) Sudoku res[j] = []; Column-row invert res[j][i] = row[j]; Birthday paradox } } return res; }; // Just zip-it _.zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]); -> [moe,30,true], [larry,40,false], [curly,50,false]
  • 12. var min = 1, // 1th January max = 365; // 31 December Live // produce birthdays var getNextBirthday = function() { Chaining return _.random(min, max); Sudoku }; Column-row invert // check for double dates Birthday paradox var isMatchFound = function(lst) { return lst.length > _.uniq(lst).length; }; // Birthday paradox (BP) - probability theorie // loop until first hit // Some have the same brithday: var getFirstHit = function() { // 100% - 366 people needed. -> 365 in 'normal' var loop = function(lst) { year lst.push(getNextBirthday()); // BP -> 99% 57 people if (IsMatchFound(lst)) { return lst.length; // attempts // BP -> 50% 23 people } else { return loop(lst); } }; return loop([]); // start };