Sorting an array by category names
来源:互联网 发布:mac 网桥 编辑:程序博客网 时间:2024/06/10 21:44
1、a = [ {id: 3, category_name: "Horror"}, {id: 4, category_name: "Non-Fiction"}, {id: 5, category_name: "LGBT"}, {id: 6, category_name: "Romance"}, {id: 7, category_name: "Romance"}]categories_sorted = [ "Romance", "LGBT", "Non-Fiction", "Horror"]p a.sort_by { |h| [categories_sorted.index(h[:category_name]), h[:id]] }
2、a.group_by { |h| h[:category_name] }.values_at(*categories_sorted).flatten
0 0
- Sorting an array by category names
- Sorting array elements by date
- Sorting array elements by date
- Partially sorting an array in Ruby
- Sorting an array of hash in Ruby
- divide an array by the size
- Type name is discouraged. By convention, Java type names usually start with an uppercase letter
- Type name is discouraged. By convention, Java type names usually start with an uppercase letter
- How to sort an array by its index? (SortIndex)
- Ruby: Sorting an array of strings, in alphabetical order, that includes some arrays of strings
- VS2013 Git 无法 push:An error was raised by libgit2. Category = Net (Error)
- 三维数组按key排序 Sorting a 3-dimensional array by a key in PHP
- Sorting Numerically: Array.NUMERIC
- Sorting Json Array
- GeeksforGeeks Sort an array according to the order defined by another array
- pku1674 Sorting by Swapping
- sorting map by value
- sorting by fields
- 算法和数据结构就是编程的一个重要部分,你若失掉了算法和数据结构,你就把一切都失掉了
- 聚合关系与组合关系
- 地址转换函数inet_aton、 inet_ntoa、 inet_addr和inet_pton 、inet_ntop
- 再析spring注解事务之事务传播
- ORACLE中RECORD、VARRAY、TABLE的使用详解
- Sorting an array by category names
- 不借助第三方插件利用ScrollView自身delegate实现下拉刷新和上拉加载
- html5手势滑动实现(单点)
- 1011. A+B和C
- IIS7备份还原
- 基于SVM和神经网络的车牌识别
- LSTM简介以及数学推导(FULL BPTT)
- Android界面
- 挑灯熬夜看《Build 2015 Keynote》图文笔记