some demos

import '../css/detail.css';// 找到字符串中重复次数最多的字符
function findMax(str) {let maxChar = '';let maxValue = 1;if (!str.length) return;let arr = str.replace(/\s/g, '').split('');let obj = {};for (let i = 0; i < arr.length; i++) {if (!obj[arr[i]]) {obj[arr[i]] = 1;} else {obj[arr[i]]++;}}let keys = Object.keys(obj);for (let j = 0; j < keys.length; j++) {if (obj[keys[j]] > maxValue) {maxValue = obj[keys[j]];maxChar = keys[j];}}return {maxChar, maxValue}
}function findMax1() {let maxChar = '';let maxValue = 1;let h = {};if (!str.length) return;let arr = str.replace(/\s/g, '').split('');for (let i = 0; i < arr.length; i++) {let a = arr[i];h[a] === undefined ? h[a] = 1 : h[a]++;if (h[a] > maxValue) {maxChar = a;maxValue = h[a];}}return {maxChar, maxValue}
}function findMax2() {let maxChar = '';let maxValue = 1;if (!str.length) return;let arr = str.replace(/\s/g, '').split('');let obj = arr.reduce((acc, curVal) => {acc[curVal] ? acc[curVal]++ : acc[curVal] = 1;if (acc[curVal] > maxValue) {maxChar = curVal;maxValue = acc[curVal];}return acc;}, {}) return {maxChar, maxValue}
}

/* \d 任意一个数字,0~9 中的任意一个\w 任意一个字母或数字或下划线,也就是 A~Z,a~z,0~9,_ 中任意一个\s 包括空格、制表符、换页符等空白字符的其中任意一个
. 小数点可以匹配除了换行符(\n)以外的任意一个字符 
*/
function findMax3(str) {let maxChar = '';let maxValue = 1;if (!str.length) return;let arr = str.replace(/\s/g, '').split('');let obj = {};str.replace(/\s/g, '').replace(/(\w)/g, (word, p) => {obj[p] ? obj[p]++ : obj[p] = 1;if (obj[p] > maxValue) {maxValue = obj[p];maxChar = p;}});return {maxChar, maxValue}}function findMax4(str) {let maxChar = '';let maxValue = 1;if (!str.length) return;let arr = str.replace(/\s/g, '').split('');Array.prototype.getMost = function() {let obj = this.reduce((acc, cur) => {acc[cur] ? acc[cur]++ : acc[cur] = 1;acc.max = acc[cur] > acc.max ? acc[cur] : acc.max;acc.key = acc[cur] > acc.max ? cur : acc.key;return acc;}, {});return obj;}// return arr.getMost();
}const str = 'this is a test 222222 ts project. skajdf; 222sldjfwel p'
const reducer = (accumulator, currentValue, b, c) => {let obj = {};obj[b] = currentValue;return obj;
}
const array1 = [1, 2, 3, 4];
// console.log(array1.reduce(reducer));console.log(findMax(str));
console.log('findMax1', findMax4(str));

/*** 输入一个整形数组,数组里有正数也有负数。数组中连续的一个或多个整数组成一个子数组,每个子数组都有一个和。 求所有子数组的和的最大值,要求时间复杂度为O(n)。*/
function findMaxSubArr(arr) {console.log(arr)let max = arr[0];let currSum = 0;for (let i = 0; i < arr.length; i++) {if (currSum < 0) {currSum = arr[i];} else {currSum += arr[i]; }if (currSum > max) {max = currSum;}}return max;
}// console.log('maxsubarr', findMaxSubArr([1, -2, 3, 10, -4, 7, 2, -5]));
// 输出结果
console.log('begin');
setTimeout(() => {console.log('settimeout 1')Promise.resolve().then( () => {console.log('promise 1')setTimeout(() => {console.log('settimeout 2');});}).then(() => {console.log('promise 2');})
}, 0);
console.log('end');
/*** 类数组转成数组*/
const nodes = document.querySelectorAll('div');
// nodes.map(item => {});// 1.for直接遍历// 2.这种方法是借用了数组原型中的slice方法,返回一个数组
Array.prototype.slice.call(nodes).map(item => {});
[].slice.call(nodes).map(item => {console.log()});// 3.Array.from() 方法从一个类似数组或可迭代对象中创建一个新的数组实例。
Array.from(nodes).map(item => {})// 4.同样是ES6中新增的内容,扩展运算符(…)也可以将某些数据结构转为数组
const nodeList = [...nodes];
function getlist(a,b,c,d) {// console.log(arguments);// console.log([...arguments][0])
}
getlist(11, 2, 3, 4);
// 使用reduce方法实现forEach、map、filter
const arr1 = [12, 21, 3];
const arr2 = arr1.map(function(item) {// console.log(this, item)return item*2
}, { msg: 'mapping' })
// console.log(arr1, arr2)
// github上的
Array.prototype.selfMap = function () {const ary = thisconst result = []const [ fn, thisArg ] = [].slice.call(arguments)if (typeof fn !== 'function') {throw new TypeError(fn + 'is not a function')  }for (let i = 0; i < ary.length; i++) {result.push(fn.call(thisArg, ary[i], i, ary))}return result
}Array.prototype.reduceMap = function (fn, thisArg) {// return (list) => {// 不怎么愿意写下面这两个判断条件const list = thisif (typeof fn !== 'function') {throw new TypeError(fn + 'is not a function')  }if (!Array.isArray(list)) {throw new TypeError('list must be a Array')}if (list.length === 0) return []return list.reduce((acc, value, index) => {return acc.concat([ fn.call(thisArg, value, index, list) ])}, [])// }
}
// mine
Array.prototype.imitateMap = function () {const list = this;const result = []const [fn, thisArg] = [].slice.call(arguments)if (typeof fn !== 'function') {throw new TypeError(fn + 'is not a function');}for (let i = 0; i < list.length; i++) {result.push(fn.call(thisArg, list[i], i, list));}return result;
}Array.prototype.imitateReduceMap = function () {const list = this;const result = []const [fn, thisArg] = [].slice.call(arguments)if (typeof fn !== 'function') {throw new TypeError(fn + 'is not a function');}if (!Array.isArray(list)) {throw new TypeError(list + 'is not a Array');}return list.reduce((acc, curValue, index) => {return acc.concat([fn.call(thisArg, curValue, index, list)]);}, [])
}
const imitateReduceMap1 = function (fn, thisArg) {return (list) => {const result = []if (typeof fn !== 'function') {throw new TypeError(fn + 'is not a function');}if (!Array.isArray(list)) {throw new TypeError(list + 'is not a Array');}return list.reduce((acc, curValue, index) => {return acc.concat([fn.call(thisArg, curValue, index, list)]);}, [])}
}console.log('imitateMap', arr1, arr1.imitateMap(function(item) {console.log('imitateMap this', this)return item + 1
}, { msg: 'mapping' }) )
console.log('imitateReduceMap', [ 1, 2, 3 ].imitateReduceMap(x => x + 1));
console.log('imitateReduceMap1', imitateReduceMap1(x => x + 1)([ 1, 2, 3 ]));
/*** 实现repeat方法*/
function repeat(func, times, wait) {return (str) => {let count = 0;const timer = setInterval(() => {if (count < times) {// func.call(this, str);count++;} else {clearInterval(timer);}}, wait);}
}const repeatFunc = repeat(alert, 3, 2000)repeatFunc('helloworld');
/*** 实现一个简单的双向绑定* 1.发布-订阅模式* 2.脏值检测* 3.数据劫持* Vue.js 采用的是 数据劫持+发布/订阅模式 的方式,通过 Object.defineProperty() 来劫持各个属性的 setter/getter, 在数据变动时发布消息给订阅者(Wacther), 触发相应的监听回调*/
// 基于Object.defineProperty 实现数据劫持,利用了对Vue.js实现双向绑定的思想
const obj = {}
Object.defineProperty(obj, 'txt',{get:function(){return obj},set:function(newValue){document.getElementById('txt').value = newValuedocument.getElementById('show-txt').innerHTML = newValue}
})
document.addEventListener('keyup', function(e){obj.txt = e.target.value
})

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/280253.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

WPF 实现视频会议与会人员动态布局

WPF 实现视频会议与会人员动态布局控件名&#xff1a;SixGridView作 者&#xff1a;WPFDevelopersOrg - 驚鏵原文链接[1]&#xff1a;https://github.com/WPFDevelopersOrg/WPFDevelopers框架使用.NET40&#xff1b;Visual Studio 2019;接着上一篇是基于Grid实现的视频查看感…

chromebook刷机_如何获取Android应用以查看Chromebook上的外部存储

chromebook刷机Android apps are a great way to expand the sometimes limited capabilities of Chromebooks, but they can be a problem if you store most of your data on an external medium—like an SD card, for example. Android应用程序是扩展Chromebook有时有限功能…

android 指纹添加_如何将手势添加到Android手机的指纹扫描仪

android 指纹添加So you have a shiny new Android phone, equipped with a security-friendly fingerprint scanner. Congratulations! But did you know that, while useful on its own, you can actually make the fingerprint scanner do more than just unlock your phone…

百度高管:问心无愧

1月23日下午消息&#xff0c;今天下午&#xff0c;百度召开百家号2019内容创作者盛典&#xff0c;百度副总裁沈抖出席并发布演讲。 就在前一天&#xff0c;一篇名为《搜索引擎百度已死》的文章刷屏&#xff0c;文中提到百度搜索有一半以上会指向百度自家产品&#xff0c;尤其百…

Vuex 学习笔记

Vuex 是什么&#xff1f; Vuex 是一个专为 Vue.js应用程序开发的状态管理模式。由于SPA应用的模块化&#xff0c;每个组件都有它各自的数据&#xff08;state&#xff09;、视图&#xff08;view&#xff09;和方法&#xff08;actions&#xff09;&#xff0c;当项目内容越来越…

xdf文档怎么转换为pdf_如何将PDF文件和图像转换为Google文档文档

xdf文档怎么转换为pdfYou probably know you can create and edit documents with Google Docs, but you can edit more than just .doc files. Google Drive can also convert any PDF, JPG, PNG, or GIF into a document with fully editable text. Here’s how. 您可能知道可…

在现代 Windows 上使用经典 Windows 2000、XP、Vista 任务栏

你好&#xff0c;这里是 Dotnet 工具箱&#xff0c;定期分享 Dotnet 有趣&#xff0c;实用的工具和组件&#xff0c;希望对您有用&#xff01;前言您第一次使用的 Windows 是哪个版本的&#xff1f;我最早使用的 Windows XP&#xff0c;然后再经过 XP、7、8/8.1 、Windows 10&a…

airdroid黑屏_如何使用AirDroid从PC控制Android设备

airdroid黑屏AirDroid for Android replaces your USB cable for connecting to your PC. Transfer files back and forth, send text messages, play music, view your photos, and manage applications using a web browser or a desktop client. 适用于Android的AirDroid取代…

分析java程序

2019独角兽企业重金招聘Python工程师标准>>> 最近公司的一个账单推送的服务&#xff0c;发现有延迟。我排查的时候发现&#xff0c;有一个程序日志不动了&#xff08;采用消息队列&#xff0c;部署了两台服务器来负载均衡&#xff09;。 网上说&#xff1a; jstack …

环境部署(九):linux下安装python+chrome+Xvfb

在基于selenium进行的UI自动化测试中&#xff0c;开发调试环境一般都是windows操作系统。完成后需要部署到专门的测试环境。 如要要部署到linux环境的服务器&#xff08;阿里云、腾讯云&#xff09;执行&#xff0c;那么测试脚本也需要对应的浏览器支持&#xff0c; 才能正常进…

地理围栏_什么是“地理围栏”?

地理围栏The term is popping up more frequently in news articles, appearing in product manuals, and highlighted as a feature in tons of mobile applications, but what exactly is geofencing? Read on as we explain what it is, why it’s appearing in more produ…

嵌套映射

1. 多对一嵌套查询映射使用案例 package com.zixue.dao;import com.zixue.annotation.MyBatisRepository; import com.zixue.entity.Emp;/*** 员工表的DAO组件* */ MyBatisRepository public interface EmpDao {void save(Emp emp);Emp findById(int id);Emp findById2(int id)…

gopro dataset_如何将GoPro安装到DSLR相机

gopro datasetIf you have a DSLR camera with a hot shoe, it’s easy to attach various flashes and other accessories right to your camera. But with a couple of cheap attachments on hand, you can mount your GoPro to your DSLR camera as well. 如果您的DSLR相机带…

jQuery已经过时了,还需要学吗?

说起jQuery&#xff0c;很多刚参加工作的程序员都没用过&#xff0c;甚至没听过。曾几何时jQuery可是秒杀一切Js库&#xff0c;大有一统江山的情况&#xff0c;可是在顶峰的时候&#xff0c;瞬间被Vue、React、Angela三大框架斩于马下。从百度指数&#xff0c;我们也看出在2015…

Bootstrap01

Bootstrap01内容概要 一.使用Bootstrap的步骤 1.下载Bootstrap类库,包含三个部分,fonts,css,Bootstrap 2.导入项目中,在头部引入JQ,css和Bootstrap 注意:JQ要引入在Bootstrap前面! 3.使用css样式时,全部使用class属性 二.全局CSS概要 1.仅支持H5文档格式 2.移动设备优先,需要在…

ios raise_如何在iOS 10中关闭“ Raise to Wake”

ios raiseRaise to Wake is a new Lock screen feature available in iOS 10. It allows you to wake your phone’s screen simply by picking up your phone. This feature is on by default, but if you’d rather not use it, it’s simple to turn off. “唤醒”是iOS 10中…

资源调度器调研

2019独角兽企业重金招聘Python工程师标准>>> 场景描述&#xff1a; 异步触发和Crontab触发 YARN(Yet Another Resource Negotiator)Hadoop 资源管理器 主要构成&#xff1a; RM(ResourceManager)是一个全局的资源管理器&#xff0c;负责整个系统的资源管理和分配。…

WPF-19 IValueConverter接口

我们先来看看微软官方给出的定语&#xff1a;提供将自定义逻辑应用于绑定的方法&#xff0c;我们来看一下该接口的定义&#xff0c;Convert提供了将数据源到UI的格式化&#xff0c;ConvertBack表示反向namespace System.Windows.Data {//// Summary:// Provides a way to a…

使用 Azure CLI 将 IaaS 资源从经典部署模型迁移到 Azure Resource Manager 部署模型

以下步骤演示如何使用 Azure 命令行接口 (CLI) 命令将基础结构即服务 (IaaS) 资源从经典部署模型迁移到 Azure Resource Manager 部署模型。 本文中的操作需要 Azure CLI。 Note 此处描述的所有操作都是幂等的。 如果你遇到功能不受支持或配置错误以外的问题&#xff0c;建议你…

黑苹果不能imessage_如何修复iMessage在iOS 10中不显示消息效果

黑苹果不能imessageiMessage got a huge update in iOS 10, adding things like third-party app integration, rich links, and a number of fun graphical effects for messages. If you’re seeing messages that say something like “(sent with Invisible Ink)” instead…