ビジネスアプリケーション
3197 ワード
関数式プログラミング、実戦練習!
カートの使用例
ケース
sizes:array[]
のnameと一致するものであれば、その物品の数と価格を加算 const server = [
{
id: 1,
sizes: [{ size: "L", name: "item", price: 1000, quantity: 1 }],
},
];
const addToCart = [
{
id: 1,
sizes: [{ size: "L", name: "item", price: 1000, quantity: 2 }],
},
{
id: 2,
sizes: [{ size: "XL", name: "item2", price: 1000, quantity: 1 }],
},
];
addToCart와 server를 비교해서 새로운 배열 만듦
const result = [
{
id: 1,
sizes: [{ size: "L", name: "item", price: 3000, quantity: 3 }],
},
{
id: 2,
sizes: [{ size: "XL", name: "item2", price: 1000, quantity: 1 }],
},
];
スタート!

getIntersectionByKey
関数でサーバーデータとローカルデータを比較し、重なっている子どもがいるかどうかを見つけます.
curry2
の場合、2つ以上の因子があれば使えるようです(不正確)fxjsの
intersectionWith
リピートアイテムを探す.intersectionWith
非使用時は以下のように使用可能
getTupleByKey
関数作成サーバと重複するローカルデータとサーバデータ

getTupleByKey
関数は、パラメータに移動したキーでインデックスを作成したオブジェクトを使用してtupleを返します.
これまでの結果,2列目の1列目はサーバ,2列目はローカルであった.
これで、
getAddedSizesQuantity
という関数を作成し、同じサイズの間に数量、価格を追加します.

getAddedSizesQuantity
関数が少し複雑です.addSizesQuantity
地図を回す.addSizesQuantity
ローカルとサーバデータのサイズ配列を用いてキーが重なるデータを検索する.初めてやったことと同じsumOfProperites
関数を実行します.getMerged
は、マージのサイズをサーバデータとマージする関数です.
sumOfProperites
objectの属性の数字で、数字とは数字を加算する関数です.
getMerged
関数とサーバデータのサイズを加算できるようになりました.
getMerged
は、調音を受けてサーバデータのみを抽出し、サイズとマージして地図でサイズをマージする関数です.
ダダダダ~!頭が爆発するから、今日は休みだ...
助かります@崔俊
Reference
この問題について(ビジネスアプリケーション), 我々は、より多くの情報をここで見つけました https://velog.io/@dongha1992/함수형-프로그래밍-실무-적용テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol