Find a matching element in a list and move to first: A journey from a novice JavaScript to an elegant TypeScript solution

const users = [
{ firstName: 'Jane', lastName: 'Foo' },
{ firstName: 'John', lastName: 'Bar' },
{ firstName: 'Jill', lastName: 'Err' }
]
const users = [
{ firstName: 'John', lastName: 'Bar' },
{ firstName: 'Jane', lastName: 'Foo' },
{ firstName: 'Jill', lastName: 'Err' }
]
$ node step1
$ npm init -y
$ npm i typescript
{
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"rootDir": ".",
"moduleResolution": "node",
"outDir": "build",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}
$ npm run build
$ node build/step6
interface User {
firstName: string
lastName: string
}
interface Product{
name: string
description: string
price: number
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store