{"ScriptPreparationCode":"var wallets = [\r\n {\r\n currency: {\r\n id: \u0022USD\u0022\r\n }\r\n },\r\n {\r\n currency: {\r\n id: \u0022IDR\u0022\r\n }\r\n },\r\n {\r\n currency: {\r\n id: \u0022SGD\u0022\r\n }\r\n },\r\n]","TestCases":[{"Name":"Old Code","Code":"const moveCurrencyToFirst = (wallets, currencyId) =\u003E {\r\n const currencyIdx = wallets.findIndex(\r\n (wallet) =\u003E wallet.currency.id === currencyId\r\n );\r\n const tempWallets = [...wallets];\r\n\r\n if (currencyIdx !== -1) {\r\n const currWallet = wallets[currencyIdx];\r\n tempWallets.splice(currencyIdx);\r\n tempWallets.unshift(currWallet);\r\n }\r\n return tempWallets;\r\n};\r\n\r\nconsole.log(moveCurrencyToFirst(wallets, \u0022SGD\u0022))","IsDeferred":false},{"Name":"New Code","Code":"const moveCurrencyToFirst = (wallets, currencyId) =\u003E {\r\n if(!wallets.length) return [];\r\n \r\n return wallets.reduce((result, wallet) =\u003E {\r\n if(wallet.currency.id === currencyId) {\r\n return [wallet, ...result]\r\n }\r\n \r\n return [...result, wallet]\r\n }, [])\r\n};\r\n\r\nconsole.log(moveCurrencyToFirst(wallets, \u0022SGD\u0022))","IsDeferred":false}]}