Skip to content

Latest commit

 

History

History
15 lines (14 loc) · 331 Bytes

1470. 重新排列数组.md

File metadata and controls

15 lines (14 loc) · 331 Bytes
/**
 * @param {number[]} nums
 * @param {number} n
 * @return {number[]}
 */
var shuffle = function (nums, n) {
    const hash = (i) => i < n ? 2 * i : 2 * (i - n) + 1;
    return nums.reduce((results, value, index) => {
        results[hash(index)] = value;
        return results;
    }, new Array(2 * n));
};