![](https://img-blog.csdnimg.cn/20201014180756738.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
JS
JasonDecode
这个作者很懒,什么都没留下…
展开
-
js arr.every()
ispositive is a callback function need to check every element// JavaScript code for every() methodfunction ispositive(element, index, array) { return element > 0;}function func() { var arr = [11, 89, 23, 7, 98]; // Check for positive n原创 2021-09-26 23:19:15 · 726 阅读 · 0 评论 -
js arr.entries()
for (const [idx, val] of arr.entries()) { console.log(idx, val);}原创 2021-09-26 23:10:51 · 343 阅读 · 0 评论 -
JS array.entries() method
entries is used for get key, val of enumerate in pythonvar arr = ["HTML", "CSS", "JS", "Bootstrap", "PHP"];console.log(arr.entries());for (var x of arr.entries()) { console.log(x);}Object [Array Iterator] {}[ 0, ‘HTML’ ][ 1, ‘CSS’ ][ 2, ‘JS’ ][原创 2021-09-26 23:06:21 · 185 阅读 · 0 评论 -
JS copyWithin method
copyWithin(target pos to copy, start to copy, end to copy)var array = [1, 2, 3, 4, 5, 6, 7];console.log(array.copyWithin(0, 4, 6));原创 2021-09-26 23:00:26 · 83 阅读 · 0 评论 -
JS 1 slice, 2 split, 3 include
1 slice is use for slice a string2 split is the same as python, with limit3 include is the same with startswith in python4 map and filter is used for functions inside5 concat is used for concat arrays// slice(startindex, endindex), not include endinde原创 2021-09-26 22:48:58 · 88 阅读 · 0 评论 -
react: hooks
1 useStateimport { useState } from 'react';export const App = () => { const [count, setCount] = useState(0); return ( <button onClick={() => setCount(count + 1)}> {count} </button> )}export default App;原创 2021-09-12 01:55:51 · 69 阅读 · 0 评论 -
JS: map, reduce and filter
// ################### *1* ###################const items = [1, 3, 5];const Square = (i) => { return { item: i, square: i * i, };};const itemsAndSquare = items.map(Square);console.log(itemsAndSquare);// ################### *2* ####原创 2021-09-11 22:03:23 · 63 阅读 · 0 评论 -
JS基础语法与类的用法
// ################### *1* ###################const { constant } = require("lodash");// const define an immutable valueconst constValue = 'hey';// let defines mutable valuelet variableValue = 0;// var is an old version of JS to define scope of valu原创 2021-09-11 15:52:02 · 61 阅读 · 0 评论 -
2. Add Two Numbers
/** * Definition for singly-linked list. * function ListNode(val, next) { * this.val = (val===undefined ? 0 : val) * this.next = (next===undefined ? null : next) * } *//** * @param {ListNode} l1 * @param {ListNode} l2 * @return {ListNode.原创 2020-12-11 23:32:08 · 223 阅读 · 0 评论 -
13. Roman to Integer
method1: 之前的太繁琐这样写不符合程序设计,虽然可读,但不简洁。class Solution: def romanToInt(self, s: str) -> int: num = 0 i = 0 while i < len(s): if i < len(s) and s[i] == 'M': num += 1000 i += 1原创 2021-09-06 23:58:01 · 47 阅读 · 0 评论 -
JS四种条件语句和六种循环语句
// 1 iflet hour = 10;if (hour < 18) { console.log('good day');}// 2 if elselet hour = 18;if (hour < 18) { console.log('good day');} else { console.log("ok");}// 3 if... else if... elselet time = 9;if (time < 10) { gre原创 2021-09-06 20:44:48 · 73 阅读 · 0 评论 -
JS 常用数学方法
console.log(Math.round(5.5));console.log(Math.ceil(5.5));console.log(Math.floor(5.5));console.log(Math.trunc(5.5)); // Returns the integer part of xconsole.log(Math.pow(8, 2));console.log(Math.sqrt(64));console.log(Math.abs(-31));console.log(Math.mi原创 2021-09-06 19:33:02 · 132 阅读 · 0 评论 -
css quiz1
CSS Quiz ResultsScore: 24 of 2596% Correct:Question 1:What does CSS stand for?Cascading Style Sheets Your answer Creative Style SheetsComputer Style SheetsColorful Style SheetsQuestion 2:What is the correct HTML for referring to an external原创 2021-09-05 23:38:14 · 212 阅读 · 0 评论 -
HTML pre tag保留原输入格式
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Page Title&原创 2021-09-04 14:17:56 · 326 阅读 · 0 评论 -
HTML quiz1
HTML Quiz ResultsScore: 33 of 4082% Correct:Question 1:What does HTML stand for?Hyper Text Markup Language Your answer Hyperlinks and Text Markup LanguageHome Tool Markup LanguageQuestion 2:Who is making the Web standards?The World Wide Web原创 2021-09-04 12:59:59 · 452 阅读 · 0 评论 -
JS 创建object三种方法和复用
var student0 = { firstName: "Will", lastName: "Smith"}console.log(student0);var student = new Object();student.firstName = "Will";student.lastName = "Smith";console.log(student);var student2 = {};student2.firstName = "Will";student2.lastName原创 2021-09-01 17:28:14 · 130 阅读 · 0 评论 -
JS function 四种写法
function area(length, width) { return length * width;}console.log(area(2, 3));const area1 = function(length, weight) { return length * weight;}console.log(area1(2, 3));const area2 = (length, weight) => { return length * weight;}console.l原创 2021-09-01 17:18:26 · 584 阅读 · 0 评论 -
JS计算器
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Calcula原创 2021-08-30 19:07:09 · 95 阅读 · 0 评论 -
19. Remove Nth Node From End of List
method: 2 pass1 first pass count number of nodes2 second pass remove nodePython:class Solution: def removeNthFromEnd(self, head: Optional[ListNode], n: int) -> Optional[ListNode]: p = q = dummy = ListNode(0) dummy.next = head原创 2021-08-30 18:31:21 · 50 阅读 · 0 评论 -
15. 3Sum - 16. 3Sum Closest - 18. 4Sum
method: 2 pointers1 prepare a set2 sort the array3 for each i loop, use 2 pointers to reduce time in sorted array4 use set to avoid repeatingPython:class Solution: def threeSum(self, nums: List[int]) -> List[List[int]]: output = set()原创 2021-08-30 18:15:02 · 89 阅读 · 0 评论 -
3. Longest Substring Without Repeating Characters
Longest Substring Without Repeating CharactersMediumGiven a string s, find the length of the longest substring without repeating characters.Example 1:Input: s = “abcabcbb”Output: 3Explanation: The answer is “abc”, with the length of 3.Example 2:I.原创 2021-01-17 18:17:51 · 96 阅读 · 0 评论 -
JS - String method
const name = 'John';const age = 30;console.log('My name is ' + name + ' and I am ' + age);console.log(`My name is ${name} and I am ${age}`);console.log(name.length);console.log(name.toLowerCase());console.log(name.toUpperCase());console.log(name.su原创 2020-12-27 22:50:43 · 105 阅读 · 0 评论 -
Javascript入门学习
Javascript for beginners1 print Hello world!console.log("Hello world!");2 comment your code2.1 in-line commentconsole.log("Hello world!"); // in-line comment2.2 multi-line comment/*console.log("Hello\n");console.log("world!\n");*/3 dat原创 2020-12-17 17:49:40 · 1422 阅读 · 0 评论 -
JS - functions - all types
JS functions1 powerfunction pow(x, y){ let total = 1; for(let i = 0; i < y; i++){ total *= x; } return total;}console.log(pow(3, 3));let myFunc = function (x, y){ let total = 1; for(let i = 0; i < y; i++){原创 2020-12-12 22:01:58 · 154 阅读 · 2 评论 -
JavaScript 基础教程
定义变量var age;age = 50;console.log(age)var age = 50;console.log(age)var age = 50;age = 25;var newAge = age;var message = "newAge = " + newAge;console.log(message);console.log(newAge);let, const and var{ let y = 10; const x = 20; .原创 2020-12-11 22:40:58 · 135 阅读 · 0 评论 -
JS - array sort, reverse and fill
{ let grades = [5, 4, 3, 2, 1]; grades.sort(); console.log(grades); grades.reverse(); console.log(grades); grades.fill(-1, 0, 2); console.log(grades);}›[1, 2, 3, 4, 5]›[5, 4, 3, 2, 1]›[-1, -1, 3, 2, 1]原创 2020-12-12 18:21:24 · 65 阅读 · 0 评论 -
JS - string 十种用法
string1 string formatlet name = 'Jason';let age = 20;let str = 'My name is ' + name + ', I am ' + age + ' years old!'console.log(str);console.log(My name is ${name}, I am ${age} years old!);2 string many lines and lengthlet text = 'This is very lon原创 2020-12-12 08:54:42 · 371 阅读 · 0 评论 -
JS - arrow functions make if concise and clean
// arrow functions make if concise and cleanconst createPerson = (name, age, gender) => { return { name: name, age, age, gender: gender };};console.log(createPerson("Zodiac", 56, "male"));// simplerconst create原创 2020-12-11 14:44:47 · 60 阅读 · 0 评论 -
JS - passing parameters form property
2. multinoulli distribution原创 2020-12-11 14:27:36 · 60 阅读 · 0 评论 -
JS - while, for, do while, random and floor
// 1 while loopvar array = [];var i = 0;while(i < 5) { array.push(i); i++;}console.log(array);// 2 for loopvar array = [];for (var i = 0; i < 5; i++) { array.push(i);}console.log(array);var array = [];for (var i = 0; i <原创 2020-12-11 13:58:43 · 61 阅读 · 0 评论 -
JS - switch more
// 1 switch morefunction testSwitch(val) { var answer = ""; switch(val) { case 1: case 2: case 3: case 4: answer = "alpha" break; case 5: case 6: answer = "beta";原创 2020-12-11 14:03:50 · 57 阅读 · 0 评论 -
JS - chain else if and switch statement
// 1 chain else iffunction testElseIf5(val) { if (val <= 100) { return "tiny"; } else if (val <= 200) { return "small"; } else if (val <= 300) { return "medium"; } else if (val <= 400) {原创 2020-12-10 09:01:44 · 145 阅读 · 0 评论 -
JS - if else and else if statement
// 1 equal or not// 3 == 3 == "3" true// 3 === "3" falsefunction compareEquality(a, b) { if (a == b) { return "Yes"; } return "No";}console.log(compareEquality(10, "10")); // string convert to numberfunction compareEquality2(a,原创 2020-12-10 08:40:37 · 150 阅读 · 0 评论 -
JS -simple if comparision
// 1 equal or not// 3 == 3 == "3" true// 3 === "3" falsefunction compareEquality(a, b) { if (a == b) { return "Yes"; } return "No";}console.log(compareEquality(10, "10")); // string convert to numberfunction compareEquality2(a,原创 2020-12-10 08:26:31 · 81 阅读 · 0 评论 -
JS - equal and ===
// 3 == 3 == "3" true// 3 === "3" falsefunction testEqual(val) { if (val == 12) { return "Yes"; } return "No";}console.log(testEqual(12))function testEqual2(val) { if (val == 12) { return "Yes"; } return "No";原创 2020-12-10 07:58:27 · 116 阅读 · 0 评论 -
JS - IF clause
function trueOrFalse(isItTrue) { if (isItTrue) { return "Yes"; } return "No";}console.log(trueOrFalse(1))function trueOrFalse2(wasThatTrue) { if (wasThatTrue) { return "yes"; } return "No";}console.log(trueOrFa原创 2020-12-10 07:49:32 · 85 阅读 · 0 评论 -
JS - 模拟队列
function nextInLine(arr, item) { arr.push(item); return arr.shift();}var testArr = [1, 2, 3, 4, 5];console.log("Before: " + JSON.stringify(testArr));console.log(nextInLine(testArr, 6));console.log("After: " + JSON.stringify(testArr));›Befo原创 2020-12-10 07:35:30 · 161 阅读 · 0 评论 -
JS - use global variables and function variables
// 1 passing parameters to functionsfunction minusSeven(num) { return num - 7;}// > 3console.log(minusSeven(10));function timesFive(num) { return num * 5;}console.log(timesFive(10));// > 50// 2 use global variables and function var原创 2020-12-10 07:01:01 · 119 阅读 · 0 评论 -
JS - local variables prioritized global variables
// local variables prioritized global variablesvar outerWear = "T-shirt";function myOutFit() { var outerWear = "sweater"; return outerWear;}console.log(myOutFit());console.log(outerWear);// ›sweater// ›T-shirt原创 2020-12-10 06:44:35 · 111 阅读 · 0 评论 -
JS - function variables can only be used inside define define
// function variables can only be used inside define definevar c = 1var d = 2function Func(a, b) { var e = 10 console.log(a + b + c + d + e);}Func(10, 5)// 28function Func2(a, b) { console.log(a - b + c + d + e);}Func2(10, 5)// Refere原创 2020-12-10 06:35:46 · 104 阅读 · 0 评论