Skip to content

Instantly share code, notes, and snippets.

class Person
attr_accessor :name
# attr_reader :name
# attr_writer :name
# def name
# @name
# end
<!DOCTYPE HTML>
<html>
<head>
<style>
body {
margin: 0px;
padding: 0px;
}
</style>
</head>
const urlDecode = function(text) {
// Put your solution here
result = {};
let splitText = text.replace(/%20/g, ' ')
.split('&')
.map(x => x.split("="));
splitText.forEach( function(elm) {
// statements
result[elm[0]] = elm[1]
const organizeInstructors = function(instructors) {
let result = {};
instructors.forEach( function(elem) {
if(!result[elem.course]) {
result[elem.course] = [];
result[elem.course].push(elem.name);
} else {
result[elem.course].push(elem.name);
}
const instructorWithLongestName = function(instructors) {
let sorted = instructors.sort(function(a, b) {
return b.name.length - a.name.length;
});
return sorted[0];
};
console.log(instructorWithLongestName([
{name: "Samuel", course: "iOS"},
let numberOfVowels = function(data) {
let count = 0;
for (var i = 0; i < data.length; i++) {
if(data[i] === 'a' || data[i] === 'e' || data[i] === 'i' || data[i] === 'o' || data[i] === 'u') {
count++;
}
}
return count;
};
let sumLargestNumbers = function(data) {
let sorted = data.sort(function(a,b){
return b - a;
})
return sorted[0] + sorted[1];
};
console.log(sumLargestNumbers([1, 10]));
console.log(sumLargestNumbers([1, 2, 3]));
console.log(sumLargestNumbers([10, 4, 34, 6, 92, 2]));
let conditionalSum = function(values, condition) {
var sum = 0;
values.forEach( function(value) {
if(condition == "even" && value % 2 === 0) {
sum += value;
} else if (condition == 'odd' && value % 2 !== 0) {
sum +=value;
}
});
return sum;
var words = ["ground", "control", "to", "major", "tom"];
const wordLen = map(words, function(word) {
return word.length;
});
const wordUpper = map(words, function(word) {
return word.toUpperCase();
});
var students = [
{ id: 1, name: "bruce", age: 40 },
{ id: 2, name: "zoidberg", age: 22 },
{ id: 3, name: "alex", age: 22 },
{ id: 4, name: "alex", age: 30 }
];
const toSortArray = students
.map(x => [x.name, x.age, x.id])