Created
May 21, 2017 09:03
-
-
Save juwencheng/de100a4afc1e9b6361fadfdb42bfe770 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/babuko
This file contains hidden or 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
<!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"> | |
// section 1 | |
// let sum = function(...args) { | |
// return args.reduce((prev,curr)=>prev + curr) | |
// }; | |
// console.log(sum(2,3,4,5)) | |
// section 2 | |
// let multiply = (mul, ...numbers) => { | |
// console.log(mul,numbers) | |
// return numbers.map((n) => { | |
// return mul*n | |
// }); | |
// }; | |
// let result = multiply(2,7,4,5) | |
// console.log(result) | |
"use strict"; | |
var numbers = [4, 6, 3, 8]; | |
// we can pass array to Math.max method, | |
// so we should change the method | |
// let max = Math.max(numbers) //error | |
// refer:http://devdocs.io/python~2.7/library/functions#apply | |
// equivalent Math.max(*args,**kwargs) | |
// let max = Math.max.apply(null, numbers) | |
// console.log(max) | |
// rewrite | |
var max = Math.max.apply(Math, numbers); | |
console.log(max); | |
// concanate | |
var newNumber = [3, 4, 34, 4].concat(numbers); | |
console.log(newNumber); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">// section 1 | |
// let sum = function(...args) { | |
// return args.reduce((prev,curr)=>prev + curr) | |
// }; | |
// console.log(sum(2,3,4,5)) | |
// section 2 | |
// let multiply = (mul, ...numbers) => { | |
// console.log(mul,numbers) | |
// return numbers.map((n) => { | |
// return mul*n | |
// }); | |
// }; | |
// let result = multiply(2,7,4,5) | |
// console.log(result) | |
var numbers = [4, 6, 3, 8]; | |
// we can pass array to Math.max method, | |
// so we should change the method | |
// let max = Math.max(numbers) //error | |
// refer:http://devdocs.io/python~2.7/library/functions#apply | |
// equivalent Math.max(*args,**kwargs) | |
// let max = Math.max.apply(null, numbers) | |
// console.log(max) | |
// rewrite | |
var max = Math.max.apply(Math, numbers); | |
console.log(max); | |
// concanate | |
var newNumber = [3, 4, 34, 4].concat(numbers); | |
console.log(newNumber);</script></body> | |
</html> |
This file contains hidden or 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
// section 1 | |
// let sum = function(...args) { | |
// return args.reduce((prev,curr)=>prev + curr) | |
// }; | |
// console.log(sum(2,3,4,5)) | |
// section 2 | |
// let multiply = (mul, ...numbers) => { | |
// console.log(mul,numbers) | |
// return numbers.map((n) => { | |
// return mul*n | |
// }); | |
// }; | |
// let result = multiply(2,7,4,5) | |
// console.log(result) | |
"use strict"; | |
var numbers = [4, 6, 3, 8]; | |
// we can pass array to Math.max method, | |
// so we should change the method | |
// let max = Math.max(numbers) //error | |
// refer:http://devdocs.io/python~2.7/library/functions#apply | |
// equivalent Math.max(*args,**kwargs) | |
// let max = Math.max.apply(null, numbers) | |
// console.log(max) | |
// rewrite | |
var max = Math.max.apply(Math, numbers); | |
console.log(max); | |
// concanate | |
var newNumber = [3, 4, 34, 4].concat(numbers); | |
console.log(newNumber); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment