Skip to content

Instantly share code, notes, and snippets.

@paschalidi
Last active December 13, 2019 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paschalidi/4ad7236b99d04ef077975034d44ac773 to your computer and use it in GitHub Desktop.
Save paschalidi/4ad7236b99d04ef077975034d44ac773 to your computer and use it in GitHub Desktop.
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