Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A simple interiew question
var people = [
{ name: 'John Hill', age: 22 },
{ name: 'Jack Chill', age: 27 }
];
var getInitials = function( name ) {
// Reusing the name argument makes little sense in general.
// We are making this assignment here for demonstrating
// the difference between value types and reference types.
name = name.split( ' ' ).map( function( word ) {
return word.charAt( 0 );
} ).join( '' );
console.log( name );
return name;
}
var increaseAge = function( person ) {
person.age += 1;
}
// Part 1: getInitials
const inititals = getInitials( people[0].name );
console.log( inititals );
console.log( people[0].name );
// Part 2: increaseAge
increaseAge( people[1] );
console.log( people[1].age );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment