var arr = [1, 2, 3, 'a', 4, 5, 'b', 9, 'n', 'm'];
arr = arr.reduceRight(function(prev, el, i) {
if (prev.length == 0 ||
(typeof(el) != typeof(prev[0][0]))) {
prev.unshift([el]);
} else {
prev[0].unshift(el);
}
return prev;
}, []);
console.log(JSON.stringify(arr));
[[1,2,3],["a"],[4,5],["b"],[9],["n","m"]]
SELECT `a`.*
FROM `a`
JOIN (
SELECT `a_id`, COUNT(*) AS `count_ab`
FROM `a_to_b`
GROUP BY `a_id`
) AS `x` ON `x`.`a_id` = `a`.`id`
JOIN (
SELECT COUNT(*) AS `count_b`
FROM `b`
) AS `b` ON `b`.`count_b` = `x`.`count_ab`
SELECT `t1`.`name`, `t2`.`name`, COUNT(*) AS `count`
FROM `teacher` AS `t1`
JOIN (
SELECT DISTINCT `teacher_id`, `student_id`
FROM `teacher_student`
) AS `s1` ON `s`.`teacher_id` = `t1`.`id`
JOIN (
SELECT DISTINCT `teacher_id`, `student_id`
FROM `teacher_student`
) AS `s2` ON `s2`.`student_id` = `s1`.`student_id` AND `s2`.`teacher_id` > `s1`.`teacher_id`
JOIN `teacher` AS `t2` ON `t2`.`id` = `s2`.`teacher_id`
GROUP BY `t1`.`id`, `t2`.`id`
ORDER BY `count`
LIMIT 1