Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What is the method of continuous filtering of js array

Shulou Source: shulou.com Published: 2022-06-01 05:03:49 10月18日 Update

This article mainly explains the "js array continuous screening processing method is what", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "js array continuous filtering processing method is what" it!

Algorithm interview questions:

There is an array [1, 1, 2, 3, 4, 5, 5, 8, 10, 22, 24, 25, 26, 66]. Please write a way to turn the array into [1, 1, 2, 3, 4, 5], 8, 10, 22, [24, 25, 26], 66].

The general idea is loop traversal, each traversal to determine whether the difference between the current item and the previous item is 1, here we need to consider if the result is 1, how to deal with, the result is not 1 how to deal with.

The result is not 1, we can insert the current item directly into the result array, but here we need to consider the boundary problem, we set two variables, the first variable array length len, the second variable array traversal start position I, for convenience, we set I to 1.

The code is as follows:

Var len = arr.length

Var res = []

For (var I = 1; I

Tags: Arrays results differences methods processing code antecedents variables loops again learning observation content that is ideas tags questions and then two positions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Shulou Information MariaDB NVidia Docker