moi65
8/1/2017 - 6:19 AM

JS Bin // source https://jsbin.com/xokoma

JS Bin

// source https://jsbin.com/xokoma

'use strict';

const _l = console.log;
_l("Starting...");

const TS = `If time is less than 10:00, create a "Good morning" greeting, if not, but time is less than 20:00, create a "Good day" greeting, otherwise a "Good evening":`

function TextCleaner(text, lower) {
      var lower = lower || true;

      var resultText = text.replace(/(^[\\("']+)|([,:;.?!#)"'|\\]+$)/, '');
      if (lower) resultText = resultText.toLowerCase();

      return resultText;
  }

console.log(TextCleaner(TS));

//------------------------------------------------------------------------------
/*
  Immediately Invoked Function Expressions (IIFE, pronounced iffy)
*/

var global = 60;

(function() {
    _l("Happy JavaScripting!!");
    _l(global===60);
    var local = 56; 
    global+=local;
    
    function sayHi(who) {
      if (who === undefined) who = 'me' 
       _l(who)  
    }
    
    sayHi();

}());

// _l(local === undefined);
_l(global);

_l(sayHi());


//------------------------------------------------------------------------------
function retour1() {
  console.log('Retour 1');
}

function retour2() {
  console.log('Retour 2');
}

function test(fct_retour) {
  fct_retour(); // appel de la fonction
}

test(retour1); // affiche 'Retour 1'
test(retour2); // affiche 'Retour 2'

function functionOne(x) { console.log(x); }

function functionTwo(var1, callback) {
    callback(var1);		
}

functionTwo(2017, functionOne);

//
function functionTree(var1, var2, callback) {
    callback(var1);	
    callback(var2);	
}

console.log('functionTree')
functionTree(2017,1, functionOne);

//
console.log('functionFor')
function functionFor(var1, var2, callback) {

    if(var1 > var2)  {
		     callback(var1);
				 var var2 = "Juste"	  
				 callback(var2);	
		} else {
		 callback("FAUX");	
		}
}

functionFor(2017,1, functionOne);
functionFor(2017,2018, functionOne);

var a = [
  "We're up all night 'til the sun",
  "We're up all night to get some",
  "We're up all night for good fun",
  "We're up all night to get lucky"
];

// Sans la syntaxe des fonctions fléchées 
var a2 = a.map(function(s){ return s.length; });

// Avec, on a quelque chose de plus concis
var a3 = a.map( s => s.length );

console.log(a2, a3)
// -----------------------------------------------------------------------------

function sayHi() {
  for(var i=0; i<arguments.length; i++) {
   console.log("Hi, " + arguments[i])
  }
}
 
sayHi("Cat", "Alice")  // 'Hi, Cat', then 'Hi, Alice'

// -----------------------------------------------------------------------------

console.log('== function Match ==')

function functionM(x) { console.log(">> ", x); }

function functionMatch(var1, var2, callback) {

    if 	(typeof var1 === 'object') {
		        console.log('== type OBJECT ==')
		      	var résultat = var1.test(var2);
            callback(résultat); // true
            return résultat
		}


    if (typeof var1 === 'string' ) {
		         console.log('== type STRING ==')
		
	   if( var1 === var2[2])  {
		     callback(var1);
				 var var2 = "Juste"	  
				 callback(var2);	
		} else {
		 callback("FAUX");	
		}  
		}
}

functionMatch('We\'re up all night for good fun', a, functionM);
functionMatch(/We're up all night for good \w+/, a, functionM);

function splitByWordCount(str, count) {
  var arr = str.split(' ')
  var r = [];
  while (arr.length) {
    r.push(arr.splice(0, count).join(' '))
  }
  return r;
}

var a = "This is a test this is a test";
console.log(splitByWordCount(a, 3))
console.log(splitByWordCount(a, 2))


function is_alphaNumeric(str)
{
 regexp = /^[A-Za-z0-9]+$/;
  
        if (regexp.test(str))
          {
            return true;
          }
        else
          {
            return false;
          }
}

console.log(is_alphaNumeric("37828sad"));

console.log(is_alphaNumeric("3243#$sew"));
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>

<script id="jsbin-javascript">
'use strict';

const _l = console.log;
_l("Starting...");

const TS = `If time is less than 10:00, create a "Good morning" greeting, if not, but time is less than 20:00, create a "Good day" greeting, otherwise a "Good evening":`

function TextCleaner(text, lower) {
      var lower = lower || true;

      var resultText = text.replace(/(^[\\("']+)|([,:;.?!#)"'|\\]+$)/, '');
      if (lower) resultText = resultText.toLowerCase();

      return resultText;
  }

console.log(TextCleaner(TS));

//------------------------------------------------------------------------------
/*
  Immediately Invoked Function Expressions (IIFE, pronounced iffy)
*/

var global = 60;

(function() {
    _l("Happy JavaScripting!!");
    _l(global===60);
    var local = 56; 
    global+=local;
    
    function sayHi(who) {
      if (who === undefined) who = 'me' 
       _l(who)  
    }
    
    sayHi();

}());

// _l(local === undefined);
_l(global);

_l(sayHi());


//------------------------------------------------------------------------------
function retour1() {
  console.log('Retour 1');
}

function retour2() {
  console.log('Retour 2');
}

function test(fct_retour) {
  fct_retour(); // appel de la fonction
}

test(retour1); // affiche 'Retour 1'
test(retour2); // affiche 'Retour 2'

function functionOne(x) { console.log(x); }

function functionTwo(var1, callback) {
    callback(var1);		
}

functionTwo(2017, functionOne);

//
function functionTree(var1, var2, callback) {
    callback(var1);	
    callback(var2);	
}

console.log('functionTree')
functionTree(2017,1, functionOne);

//
console.log('functionFor')
function functionFor(var1, var2, callback) {

    if(var1 > var2)  {
		     callback(var1);
				 var var2 = "Juste"	  
				 callback(var2);	
		} else {
		 callback("FAUX");	
		}
}

functionFor(2017,1, functionOne);
functionFor(2017,2018, functionOne);

var a = [
  "We're up all night 'til the sun",
  "We're up all night to get some",
  "We're up all night for good fun",
  "We're up all night to get lucky"
];

// Sans la syntaxe des fonctions fléchées 
var a2 = a.map(function(s){ return s.length; });

// Avec, on a quelque chose de plus concis
var a3 = a.map( s => s.length );

console.log(a2, a3)
// -----------------------------------------------------------------------------

function sayHi() {
  for(var i=0; i<arguments.length; i++) {
   console.log("Hi, " + arguments[i])
  }
}
 
sayHi("Cat", "Alice")  // 'Hi, Cat', then 'Hi, Alice'

// -----------------------------------------------------------------------------

console.log('== function Match ==')

function functionM(x) { console.log(">> ", x); }

function functionMatch(var1, var2, callback) {

    if 	(typeof var1 === 'object') {
		        console.log('== type OBJECT ==')
		      	var résultat = var1.test(var2);
            callback(résultat); // true
            return résultat
		}


    if (typeof var1 === 'string' ) {
		         console.log('== type STRING ==')
		
	   if( var1 === var2[2])  {
		     callback(var1);
				 var var2 = "Juste"	  
				 callback(var2);	
		} else {
		 callback("FAUX");	
		}  
		}
}

functionMatch('We\'re up all night for good fun', a, functionM);
functionMatch(/We're up all night for good \w+/, a, functionM);

function splitByWordCount(str, count) {
  var arr = str.split(' ')
  var r = [];
  while (arr.length) {
    r.push(arr.splice(0, count).join(' '))
  }
  return r;
}

var a = "This is a test this is a test";
console.log(splitByWordCount(a, 3))
console.log(splitByWordCount(a, 2))


function is_alphaNumeric(str)
{
 regexp = /^[A-Za-z0-9]+$/;
  
        if (regexp.test(str))
          {
            return true;
          }
        else
          {
            return false;
          }
}

console.log(is_alphaNumeric("37828sad"));

console.log(is_alphaNumeric("3243#$sew"));
</script>



<script id="jsbin-source-javascript" type="text/javascript">'use strict';

const _l = console.log;
_l("Starting...");

const TS = `If time is less than 10:00, create a "Good morning" greeting, if not, but time is less than 20:00, create a "Good day" greeting, otherwise a "Good evening":`

function TextCleaner(text, lower) {
      var lower = lower || true;

      var resultText = text.replace(/(^[\\("']+)|([,:;.?!#)"'|\\]+$)/, '');
      if (lower) resultText = resultText.toLowerCase();

      return resultText;
  }

console.log(TextCleaner(TS));

//------------------------------------------------------------------------------
/*
  Immediately Invoked Function Expressions (IIFE, pronounced iffy)
*/

var global = 60;

(function() {
    _l("Happy JavaScripting!!");
    _l(global===60);
    var local = 56; 
    global+=local;
    
    function sayHi(who) {
      if (who === undefined) who = 'me' 
       _l(who)  
    }
    
    sayHi();

}());

// _l(local === undefined);
_l(global);

_l(sayHi());


//------------------------------------------------------------------------------
function retour1() {
  console.log('Retour 1');
}

function retour2() {
  console.log('Retour 2');
}

function test(fct_retour) {
  fct_retour(); // appel de la fonction
}

test(retour1); // affiche 'Retour 1'
test(retour2); // affiche 'Retour 2'

function functionOne(x) { console.log(x); }

function functionTwo(var1, callback) {
    callback(var1);		
}

functionTwo(2017, functionOne);

//
function functionTree(var1, var2, callback) {
    callback(var1);	
    callback(var2);	
}

console.log('functionTree')
functionTree(2017,1, functionOne);

//
console.log('functionFor')
function functionFor(var1, var2, callback) {

    if(var1 > var2)  {
		     callback(var1);
				 var var2 = "Juste"	  
				 callback(var2);	
		} else {
		 callback("FAUX");	
		}
}

functionFor(2017,1, functionOne);
functionFor(2017,2018, functionOne);

var a = [
  "We're up all night 'til the sun",
  "We're up all night to get some",
  "We're up all night for good fun",
  "We're up all night to get lucky"
];

// Sans la syntaxe des fonctions fléchées 
var a2 = a.map(function(s){ return s.length; });

// Avec, on a quelque chose de plus concis
var a3 = a.map( s => s.length );

console.log(a2, a3)
// -----------------------------------------------------------------------------

function sayHi() {
  for(var i=0; i<arguments.length; i++) {
   console.log("Hi, " + arguments[i])
  }
}
 
sayHi("Cat", "Alice")  // 'Hi, Cat', then 'Hi, Alice'

// -----------------------------------------------------------------------------

console.log('== function Match ==')

function functionM(x) { console.log(">> ", x); }

function functionMatch(var1, var2, callback) {

    if 	(typeof var1 === 'object') {
		        console.log('== type OBJECT ==')
		      	var résultat = var1.test(var2);
            callback(résultat); // true
            return résultat
		}


    if (typeof var1 === 'string' ) {
		         console.log('== type STRING ==')
		
	   if( var1 === var2[2])  {
		     callback(var1);
				 var var2 = "Juste"	  
				 callback(var2);	
		} else {
		 callback("FAUX");	
		}  
		}
}

functionMatch('We\'re up all night for good fun', a, functionM);
functionMatch(/We're up all night for good \w+/, a, functionM);

function splitByWordCount(str, count) {
  var arr = str.split(' ')
  var r = [];
  while (arr.length) {
    r.push(arr.splice(0, count).join(' '))
  }
  return r;
}

var a = "This is a test this is a test";
console.log(splitByWordCount(a, 3))
console.log(splitByWordCount(a, 2))


function is_alphaNumeric(str)
{
 regexp = /^[A-Za-z0-9]+$/;
  
        if (regexp.test(str))
          {
            return true;
          }
        else
          {
            return false;
          }
}

console.log(is_alphaNumeric("37828sad"));

console.log(is_alphaNumeric("3243#$sew"));
</script></body>
</html>