当前位置:网站首页>Write down some written test questions
Write down some written test questions
2022-06-29 09:18:00 【swag_ Special actor】
One is known by ASCLL A string of characters , Find the first repeated character
Ideas : Each element is compared with the following elements , Exit as long as they are equal , The first repeated character has been found .
function getFirstSameStr (string) {
var i = 0
for (i; i < string.length; i++) {
for (var j = i + 1; j < string.length; j++) {
if (string[i] == string[j]) {
console.log(' The first repeated character is ', string[i])
return
} else {
continue
}
}
}
console.log(' The string has no duplicate characters ')
}
Given an array , Array elements can only be numbers ,null,undefined,NaN. Find the maximum length of the array without repetition .
for example : Input [1,4,3,4,null,undefined,NaN,null] Output 6
Ideas : Turn every element into a string , Avoided null and undefined Influence .null == undefined by true,null === undefined by false, Each element is compared with the following elements , See if there is any repetition , Find the duplicate and delete the following .
function maxSonArray (array) {
var i = 0
for (i; i < array.length; i++) {
// All converted strings are easy to compare (null == undefined by true,null === undefined by false)
array[i] = '' + array[i]
}
// console.log(' Processed array ', array)
var sonArray = array
i = 0
for (i; i < sonArray.length; i++) {
for (var j = i + 1; j < sonArray.length; j++) {
if (sonArray[i] === sonArray[j]) {
// If you find a duplicate, get rid of it
sonArray.splice(j, 1)
} else {
continue
}
}
}
console.log(' Maximum subarray length ', sonArray.length, ' The largest subarray is ', sonArray)
}
Complete the function transform(url){ } Realization url Dynamic replacement of address parameters
for example let href=‘https://www.baidu.com/s?user=teml2&&wd=teml’
console.log(transform(href)({user:‘123’,wd:‘aa’,qq:‘321’}))
Output :https://www.baidu.com/s?user=123&&wd=aa
Ideas : First find ?,? And that's followed by the parameters , Parameter use && link , We will use && Split into arrays ,= The left and right sides are key value pairs , The direct use = Split key value pairs into arrays , Replace the old parameter value with the new one , Please note that the original parameters should be used instead of the new ones . So we iterate over the original parameters key To receive new parameter values , New fields are not needed . Finally, reassemble the string .
function transform (url, param) {
// find ? This is followed by the parameter string
var paramsindex = url.indexOf('?')
// Intercept ? The preceding string
var urlHead = url.substr(0, paramsindex + 1)
// Intercept ? String after
var paramsStr = url.substr(paramsindex + 1)
// Set the parameter string as '&&' Division
var paramsArray = paramsStr.split('&&')
// Change the parameter array into a key value pair and put it into the object
var keyValObject = {
}
paramsArray.forEach((element) => {
let temp = element.split('=')
keyValObject[temp[0]] = temp[1]
});
// Merge parameter objects
let tempKeyArray = Object.keys(keyValObject)
tempKeyArray.forEach((element) => {
keyValObject[element] = param[element]
})
// To add all the parameters of the new object, you can use the next line of code
// Object.assign(keyValObject, param)
// Regroup into url
let target = ''
let temparray = Object.entries(keyValObject)
for (let i = 0; i < temparray.length; i++) {
temparray[i] = temparray[i].join('=')
}
let parambody = temparray.join('&&')
target = urlHead + parambody
console.log(target)
}
边栏推荐
- What is hyperfusion? What is the difference with traditional architecture
- Analysis of c voice endpoint detection (VAD) implementation process
- Open3D 最远点采样(FPS)
- H5 soft keyboard problem
- Training kernel switching using GPU
- Simple use of promise method
- 记自定义微信小程序顶部导航栏
- MT yolov6 training and testing
- Pointnet/pointnet++ training and testing
- pytorch总结—自动求梯度
猜你喜欢

train_on_batch保存一下loss函数变化的图像

Let you know today that the passing rate of the PMP Exam is 97%, is it believable

promise方法的简单使用

在 golang 中是如何对 epoll 进行封装的?

Picture format -webp

Let's make a summary

Verilog 大小端以及 +:使用

记微信小程序setData动态修改字段名

NPM common commands

Augfpn: amélioration de l'apprentissage des caractéristiques à plusieurs échelles pour la détection des cibles
随机推荐
网络安全问题
Augfpn: improved multiscale feature learning for target detection
Lffd: a lightweight fast face detector for edge detection
SSD改進CFENet
在 RedisTemplate 中使用 scan
Verilog 数据类型
uniapp微信小程序报错 TypeError: Cannot read property ‘call‘ of undefined
PointNet/Pointnet++训练及测试
笔试题“将版本号从大到小排列”
Verilog equivalent operator
Open3D 隐藏点移除
Wechat applet sub components transfer values to the page (communication between parent and child components) with source code
MT-yolov6训练及测试
调试H5页面-vConsole
训练查看(问题暂存)
记一些笔试题
uniapp引入组件不生效解决方法
verilog 等价操作符
Detecting and counting tiny faces
Verilog 表达式