JavaScript字符串的练习

JavaScript——字符串练习 字符串练习 题目 var str = ‘abaasdffggghhjjkkgfddssss34444343’; 字符串的长度 console.log(str.length); 取出指定位置的字符串,如:0,3,5,7,9 获取数组索引: 根据位置返回字符 ①charAt(index) var arr = [1,2,3,4,5,2,a]; console.log(arr.charAt(2)); // 结果返回3 ②charCodeAt(index)—返回字符的ascll码 console.log 阅读详情
所有都定义函数==

1. 传入任意字符串,统计字符串中的大写字母个数、小写字母个数、数字个数、其他字符个数。

------

2. 反转字符串.
   传入:"iOS Android HTML5 Java"
   返回:"avaJ 5LMTH diordnA SOi"

------

3. 去除字符串首尾空格.(写一个自定义的 trim 函数)

------

4. 创建一个长度为5-10, 内容为数字字母下滑线的随机字符串.

------

5. 验证字符串:长度4-16; 只能包含数字、英文字符、下划线三种符号; 首字符不能是数字";

------

6. 将字符中单词用空格隔开
   已知传入的字符串中只有字母,每个单词的首字母大写,请将每个单词用空格隔开
    只保留第一个单词的首字母大写

 传入:"HelloMyWorld"

 返回:"Hello my world"

---------------------------------------------------------------

当然,今天用的方法是锻炼思维的,去除正则表达式去写。

1.
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<!--题目:传入任意字符串,统计字符串中的大写字母个数、小写字母个数、数字个数、其他字符个数-->
<script>

    //全局变量
    var lowerNum=0;
    var uperNum=0;
    var number=0;
    var others=0;

    //统计字符串的各个符号的数量函数
    //一个小小的知识点需注意:字符串比较更倾向于转换成数字进行比较,只有两个操作数都是字符串的时候才会进行ASCII码转换进行比较
    function  statistics(str) {
        for(var i=0;i<str.length;i++){
            var char=str.charAt(i);
            if(char >="a" && char <= "z"){
                lowerNum++;
            }else if(char >="A" && char <= "Z"){
                uperNum++;
            }else if(char >= 0 && char <= 9){
                number++;
            }else{
                others++;
            }
        }
    }


    var str=prompt("Please input your string that your want.");
    statistics(str);
    console.log("你输入的字符串为: " + str);
    console.log("小写字母的个数: " + lowerNum);
    console.log("大写字母的个数: " + uperNum);
    console.log("数字类型的个数: " + number);
    console.log("其他符号的个数: " + others);
</script>
</body>
</html>

其实我们不应该用全局变量去搞,我们如果要传出数据,应该优先考虑对象或者数组输出,这样的想法应该培养。

另解:


        
Windows11 升级到24H2后,原本的protel99se软件的DDB图纸文件打不开解决办法 Windows11更新后无法打开DDB文件 阅读详情

相关推荐

光耦合MOSFET(Optocoupled MOSFET,简称OCMOS)

光耦合MOSFET(Optocoupled MOSFET,简称OCMOS)是一种将光电耦合器和MOSFET结合在一起的器件,用于实现电气隔离和信号传输。选择合适的光耦合MOSFET时,还需要考虑具体应用的需求和环境条件,以确保最佳性能和可靠性。- 最大输出电流和电压:确保所选型号能够满足电路的最大电流和电压需求。- 最大输出电流和电压:确保所选型号能够满足电路的最大电流和电压需求。- 隔离电压:根据应用环境的电气隔离要求选择合适的隔离电压。- 隔离电压:根据应用环境的电气隔离要求选择合适的隔离电压。

eydj2008的专栏 1731

Computer Networks 和 Computer & Security投稿经验

论文投稿

qq_50604294的博客 9235

「Debug R」在从名字空间‘XVector’中出口方法时发现了不是S4通用的函数‘parallelSlotNames’...

每当R语言版本更新,Bioconductor的版本随之更替的时候,总会有一些神奇的报错会出现,比如说下面这种。 Error: package or namespace load failed for ‘GenomicRanges’: 在从名字空间‘XVector’中出口方法时发现了不是S4通用的函数‘parallelSlotNames’ 如果读中文读不懂,我们可以把它翻译成英文。 packa...

xuzhougeng blog 2003

vCenter6.7证书过期导致503报错的全面修复指南:从STS证书更新到SSL信任修复

本文详细解析了VMware vCenter 6.7因STS证书过期导致503服务不可用错误的根本原因,并提供了从诊断、更新STS证书到修复SSL信任链的完整解决方案。通过命令行工具检查证书状态,使用官方脚本更新过期STS证书,并利用lsdoctor工具修复深层SSL信任问题,最终指导用户使用certificate-manager彻底重置所有证书,帮助管理员快速恢复vCenter服务。

pz890123的博客 1295

高云FPGA开发实战:手把手教你用ModelSim做功能仿真与时序分析(附Testbench写法)

本文详细介绍了高云FPGA开发中如何使用ModelSim进行功能仿真与时序分析,包括环境搭建、Testbench编写、波形调试和时序优化等实战技巧。通过具体案例和代码示例,帮助开发者掌握FPGA仿真验证的核心方法,提升设计可靠性。特别针对高云GW5A系列器件提供了专业的仿真库配置指南和时序分析策略。

weixin_30412167的博客 469

海康工业相机 Could not find module MvCameraControl.dll(已解决)

【代码】海康摄像机 Could not find module MvCameraControl.dll(已解决)

hmbbpdx的博客 2225

Python爬虫实战:如何抓取旅游论坛上的帖子、旅行攻略和评论内容

无论是知名的旅游网站,还是地方性的旅游讨论区,用户发布的旅行贴文、攻略和评论往往包含着大量的宝贵信息。本文将详细介绍如何使用Python编写一个爬虫,抓取旅游论坛上的帖子、旅行攻略和评论内容,涵盖从获取页面内容、解析数据到处理动态加载等各个方面的技术。从基本的请求和网页解析,到动态加载页面的处理,再到数据存储和反爬虫技巧,我们详细讲解了抓取旅游论坛数据的全过程。通过本文的介绍,你可以将所学的爬虫技术应用到其他类似的网站抓取任务中,为后续的数据分析、机器学习等任务提供丰富的数据源。在这种情况下,传统的。

2201_76125261的博客 1557

热红外图像小目标检测算法综述

热红外小目标检测算法综述,着重介绍基于深度学习的小目标检测算法

Littro Innovations 4245

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

上一篇: JavaScript的数组练习
下一篇: 原生JS实现缓动的小球案例
风或许自媒体
博客等级 码龄12年 76粉丝 35原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值