Last active
December 13, 2019 14:41
-
-
Save paschalidi/4ad7236b99d04ef077975034d44ac773 to your computer and use it in GitHub Desktop.
A simple interiew question
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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