Skip to content

Instantly share code, notes, and snippets.

@funador
Created February 8, 2018 03:24
Show Gist options
  • Save funador/5b4744a7c6d46012a446ba8419e56ccd to your computer and use it in GitHub Desktop.
Save funador/5b4744a7c6d46012a446ba8419e56ccd to your computer and use it in GitHub Desktop.
repl.it
ei-eval-retake
// =====================================================
// 1.
// Write a function called `doubleIt` which accepts a `num`
// parameter (type: number) and returns double the provided number
// Test #1
const result1 = doubleIt(10);
console.log(result1); // => 20
// =====================================================
function doubleIt(num){
return num *2
}
// =====================================================
// 2.
// Write a function called `trunkIt` which accepts a `words`
// parameter (type: string) and returns a string where everything
// after the tenth character is removed and replaced with "..."
//
// HINT: The .slice() method and concatenation will be useful here
// Test #2
const result2 = trunkIt("How much wood would a woodchuck chuck?");
console.log(result2); // => "How much w..."
// =====================================================
function trunkIt(words){
return words.slice(0,10)+"..."
}
// =====================================================
// 3.
// Write a function called `shoutThem` that accepts a `words` parameter
// (type: array) and returns a new array where all the elements have
// been transformed to ALL UPPERCASE.
// Test #3
const result3 = shoutThem(['how', 'now', 'brown', 'cow']);
console.log(result3); // => ['HOW', 'NOW', 'BROWN', 'COW']
// =====================================================
/*function shoutThem(words){
const arr =[]
for(i=0;i<words.length;i++){
arr.push(words[i].toUpperCase());
}
return arr
}
*/
// =====================================================
// 4.
// If you used a loop to solve the problem above, now use the Array
// .map() method, or vice versa.
// =====================================================
function shoutThem(words){
return words.map(function(a){
return a.toUpperCase();
})
}
// =====================================================
// 5.
// Write a function called `evalStudents` that accepts a `students`
// parameter (type: array of objects). Each object has the following
// structure:
//
// { name: 'john', credits: 71, graduated: false }
//
// Your function should check the `credits` prop on each student object.
// If the value is greater than or equal to 90, set the `graduated` prop
// to true. Otherwise, do nothing.
// Test #5
const students = [
{ name: 'john', credits: 71, graduated: false },
{ name: 'laura', credits: 95, graduated: false },
{ name: 'rich', credits: 36, graduated: false },
{ name: 'tauhida', credits: 90, graduated: false }
];
function evalStudents(students){
for(i=0;i<students.length;i++)
if(students[i].credits>=90){
students[i].graduated = true;
}
}
evalStudents(students);
console.log(students);
// =====================================================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment