# Interview with Richard
### Fix the bugs in this function that converts a list of vectors into a list of points.
```typescript
type Vector = {
dx: number,
dy; number,
};
type Point = {
x: number,
y: number,
};
/*
* Convert an array of vectors into an array of points, starting
* from (0,0), and in the same order as the array of vectors
*/
function makeAbs_(pts, v): Point[] {
return [...pts, {
x: pts[pts.length-1].x + v.dx,
y: pts[pts.length-1].y + v.dy,
}];
}
const makeAbsolute = (vs: Vector[]) =>
vs.reduce(makeAbs_, [{x: 0, y: 0}]): Point[];
```
```typescript
makeAbsolutes([{dx:1,dy:1},{dx:2,dy:2}])
[{x:0, y:0}, {x:1,y:1}, {x:3,y:3}]
makeAbs_([{x:3,y:3}, {x:1,y:1}], {dx:3,dy:3})
[{x:6,y;6},{x:3,y:3},{x:1,y:1}]
`
``typescript
[{x:1,y:1},{x:3,y:3}]
```
### Invert the case of a string.
Given a function to invert the case of a single character:
```typescript
invertChar = (char: string): string =>
char === char.toLowerCase() ? char.toUpperCase() : char.toLowerCase();
```
write a one-line function to invert the case of a string:
```typescript
invertString = (str: string): string =>new String(str.toCharArray().map(invertChar));
```
### Why doesn't 0.4 + 0.8 == 1.2? (in javascript, Java, PHP, C, etc.)
proposed solutions:
* (abs(0.4+0.8 - 1.2) < 0.00001)
* round(0.4+0.8) == round(1.2)
* -- (sign)*(number)*2^(expontent)
* 10 * 0.4 + 10* 0.8 == 10 * 1.2
### If you could program in any language, what would it be?
* depends on application
* windows desktop: visual c++ (game, etc)
* website: servside language, php, java, scala
* desktop no graphics (could use C)
* mac: ObjC vs win: visual basic / visual c++ vs sunos: java
### Given an array of numbers, return the second greatest number without using sort.
```javascript
var array = [0,3,5,1,8,6,4];
var greatest = -100000.0;
var secondgreatest = -100000.0;
var loopcounter = 0;
for( ; loopcounter < array.length; loopcounter = loopcounter + 1 ) {
var currentvalue = array[ loopcounter ];
var tempgreatest = -100000.0;
//pick greatest
if(currentvalue > greatest) {
tempgreatest = greatest;
greatest = currentvalue;
}
//currentValue = 6
//greatest = 8
//secondgreatest = 5
if(currentvalue > secondgreatest ) {
if( secondgreatest < tempgreatest ) {
secondgreatest = tempgreatest;
}else if( currentvalue < greatest ) {
secondgreatest = currentvalue;
}
}
}
### Discuss advantages vs disadvantages of (more complicated versions of)
```javascript
const max = a > b ? a : b;
```
vs.
```javascript
const max = Math.max(a,b);
```
pros of writing it out:
* if you don't have the library available
* common idiom
* makes any side effects explicit
* program space
* how much of the math library are you actually going to use?
pros of library use:
* more intuitive
* more english-like syntax, easier to read
* easier to refactor into a remote call
* reusability, consistant
* ease of refactoring