|
@@ -0,0 +1,71 @@
|
|
|
+<!DOCTYPE html>
|
|
|
+<html lang="en">
|
|
|
+<head>
|
|
|
+ <meta charset="UTF-8">
|
|
|
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
+ <meta http-equiv="X-UA-Compatible" content="ie=edge">
|
|
|
+ <title>Document</title>
|
|
|
+ <style type="text/css">
|
|
|
+ label{
|
|
|
+ display: inline-block;
|
|
|
+ width:80px;
|
|
|
+ margin-top: 15px;
|
|
|
+ }
|
|
|
+ input{
|
|
|
+ margin-top: 15px;
|
|
|
+ }
|
|
|
+ </style>
|
|
|
+</head>
|
|
|
+<body>
|
|
|
+ <div id="container"><button id="button">clic me</button>
|
|
|
+ <a href="http://google.com">google</a>
|
|
|
+ </div>
|
|
|
+ <span id='span'>coun</span>
|
|
|
+
|
|
|
+ <script type="text/javascript">
|
|
|
+ //2 sort
|
|
|
+ var persons = [
|
|
|
+ {name: "Иван", age: 17},
|
|
|
+ {name: "Мария", age: 35},
|
|
|
+ {name: "Алексей", age: 73},
|
|
|
+ {name: "Яков", age: 12},
|
|
|
+]
|
|
|
+
|
|
|
+sort(persons, "age"); //сортирует по возрасту по возрастанию
|
|
|
+sort(persons, "name", false);
|
|
|
+
|
|
|
+ function sort(arr,key,direction = true){
|
|
|
+ arr.sort(function(a,b){
|
|
|
+if (direction){
|
|
|
+ if (a[key] > b[key]){
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ return -1;
|
|
|
+}
|
|
|
+else{if (b[key] > a[key]){
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ return -1;
|
|
|
+}
|
|
|
+})
|
|
|
+}
|
|
|
+//2 array map
|
|
|
+var arr = ["1", {}, null, undefined, "500", 700]
|
|
|
+var arr1 = arr.map(x=>{
|
|
|
+if (typeof(x) =="string") { return +x}
|
|
|
+else{return x}
|
|
|
+})
|
|
|
+
|
|
|
+//3 array reduce
|
|
|
+var arr2 = arr1.reduce((x,y)=>{
|
|
|
+ if (typeof(x) =="number") {
|
|
|
+ if(typeof(y) =="number"){return x=x*y}
|
|
|
+ else{return x=x}
|
|
|
+ }
|
|
|
+ else{if(typeof(y) =="number"){return x=y}
|
|
|
+ }
|
|
|
+})
|
|
|
+
|
|
|
+ </script>
|
|
|
+</body>
|
|
|
+</html>
|