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