怎么过滤出一组号码中的顺子号码?

比如有1,2,5,6,7,11,14这组号码,怎么过滤出[1,2]和[5,6,7]这两组号码?求指点
尚方宝剑之说
浏览 435回答 2
2回答

呼唤远方

这种逻辑?vararr=[1,2,5,6,7,11,14];varlen=arr.length,before=arr[0],i=1,res=[],result=[],current;for(;i

互换的青春

这样行吗?functionsubsequence(arr){if(!arr||arr.length1){result.push(subArr);}returnresult;}//testconsole.log(subsequence([]));console.log(subsequence([0]));console.log(subsequence([1,2,5,6,7,11,14]));console.log(subsequence([1,2,3,4,7,8,9,11,23,45,56,66,67]));console.log(subsequence([9,8,7,7,8,9,0]));
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript