当前位置:网站首页>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)
}
边栏推荐
- 宏,函数和内联函数
- Did you really make things clear when you were promoted or reported?
- 微信小程序用户拒绝授权地理位置信息再次调起授权窗口
- Wechat applet project: tab navigation bar
- Jar package and war package
- MySQL row column conversion example
- (transfer) mysql: error 1071 (42000): specified key was too long; max key length is 767 bytes
- Detecting and counting tiny faces
- train_on_batch保存一下loss函数变化的图像
- 超融合架构和传统架构有什么区别?
猜你喜欢

Summary of IO streams

Lffd: a lightweight fast face detector for edge detection

Activemq消息组件发布订阅ReDelivery消息重新投递

Redo after JS rotation view (longer full version, can be run)

Open3d farthest point sampling (FPS)

记自定义微信小程序顶部导航栏

Detecting and counting tiny faces

Wechat applet wx Navigateback returns the parameters carried on the previous page

图片格式-webp

Remember to customize the top navigation bar of wechat applet
随机推荐
Using scan in redistemplate
GPU training cloud platform record
乘法器设计(流水线)verilog code
keras转tf.keras中VGG19 input_shape
Highlight in the middle of the navigation bar at the bottom of wechat applet
微信小程序wx.navigateBack返回上一页携带参数
train_on_batch保存一下loss函数变化的图像
(转)MySQL: ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes
【To .NET】C#数据模型,从Entity Framework Core到LINQ
Wechat applet project: wechat applet page layout
Mysql使用union all统计多张表组合总数,并分别统计各表数量
AugFPN:改进多尺度特征学习用于目标检测
pytorch总结学习系列-数据操作
Calculus Learning
Debugging H5 page -weinre and spy debugger real machine debugging
实例报错IOPub data rate exceeded
Cdga | what is the core of digital transformation in the transportation industry?
Wechat applet sharing page, sharing to the circle of friends
微信小程序打开文件流
ISO16000-9建筑产品和家具中挥发性有机物的测试