文章 评论 浏览 28
留个小小的见解`/**
/**
let card = {old: [],new: [1,2,3,4,5,6,7,8,9,10,11,12,13]}cardSort(card)
console.log(card) // { old: [ 1, 12, 2, 8, 3, 11, 4, 9, 5, 13, 6, 10, 7 ], new: [] }`
文章 0 评论 0
接受
留个小小的见解
`/**
*/
function pipe(...fns) {
return function(x) {
return fns.reduce(function(arg,fn) {
return fn(arg)
},x)
}
}
/**
*/
function removeNewLastToOldFirst(card) {
card.old = [card.new.pop(),...card.old];
return card;
}
/**
*/
function reverseLastToFisrt(card) {
let last = card.old.pop();
if(last) {
card.old = [last,...card.old];
}
return card;
}
/**
*/
function cardSort(card) {
if(card.new.length > 0) {
pipe(reverseLastToFisrt,removeNewLastToOldFirst)(card)
cardSort(card)
} else {
return;
}
}
let card = {
old: [],
new: [1,2,3,4,5,6,7,8,9,10,11,12,13]
}
cardSort(card)
console.log(card) // { old: [ 1, 12, 2, 8, 3, 11, 4, 9, 5, 13, 6, 10, 7 ], new: [] }`
第 126 题:扑克牌问题