{"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":"Original 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 const selectedWallet = wallets.find(\r\n (wallet) =\u003E wallet.currency.id === currencyId\r\n );\r\n \r\n let result = wallets.filter(\r\n (wallet) =\u003E wallet.currency.id !== currencyId\r\n );\r\n\r\n if (selectedWallet) {\r\n result = [selectedWallet, ...result];\r\n }\r\n\r\n return result;\r\n};\r\n\r\nconsole.log(moveCurrencyToFirst(wallets, \u0022SGD\u0022))","IsDeferred":false}]}