如果数组的元素相同,则将它们组合成子数组

时间:2018-06-14 00:50:18

标签: javascript sorting

尝试找到将执行以下操作的算法:

let input = [ 'kooty', 'dlnnoo', 'emor', 'dlnnoo', 'kooty', 'aiprs' ]

function combine(input){
  // you should return 

  [ ['kooty', 'kooty'], ['dlnnoo','dlnnoo'], ['emor'], ['aiprs'] ]
}

我通过使用Lodash得到了答案,但我想知道是否有一种方法没有

function combine(input){

  let sortedCity = [];
  let finalArr = [];


  for(let city in input){
    sortedCity.push(input[city].toLowerCase().split('').sort().join(''));
  }
  let a = lodash.groupBy(sortedCity)

  return Object.values(a)

}

combine(input)

1 个答案:

答案 0 :(得分:0)

<IfModule mod_rewrite.c>
    RewriteEngine on

    RewriteCond %{REMOTE_ADDR} xxx\.xxx\.xxx\.xxx [OR]
    RewriteCond %{REMOTE_ADDR} xxx\.xxx\.xxx\.xxy [OR]
    RewriteCond %{REMOTE_ADDR} xxx\.xxx\.xxx\.xxz
    RewriteRule .* - [L] #do notthing

    #if we are here, the IP is not in the allowed list, redirect
    RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
    RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
    RewriteRule .* /maintenance.html [R=302,L]
</IfModule>