Compare commits

..

No commits in common. "9def6b47ed87eace46a436ab444110d94c4a2ad6" and "d9bba749797b96498d619312f79f4e6bdc4d2b6a" have entirely different histories.

3 changed files with 7 additions and 107 deletions

View File

@ -89,92 +89,13 @@ console.log(numbers.reduceRight((sum, cur) => sum + cur, 0));
console.log(Array.isArray(countries))
function camelize(str){
// words = str.split('-')
// for(let i = 1; i < words.length; i++){
// words[i] = words[i][0].toUpperCase() + words[i].slice(1);
// }
// return words.join('');
return str.split('-')
.map((word, index) => index == 0 ? word: word[0].toUpperCase() + word.slice(1))
.join('')
words = str.split('-')
for(let i = 1; i < words.length; i++){
words[i][0] = words[i][0].toUpperCase();
console.log(words[i])
}
return words.join('');
}
console.log(camelize("background-color"))
console.log(camelize("list-style-image"))
console.log(camelize("-webkit-translation"))
function filterRange(arr, a, b){
return arr.filter(ele => ele >= a && ele <= b);
}
arr = [5, 3, 8, 1];
let filtered = filterRange(arr, 1, 4);
console.log(filtered)
console.log(arr)
function copySorted(arr){
return arr.slice().sort();
}
arr = ["HTML", "JavaScript", "CSS"];
let sorted = copySorted(arr);
console.log(sorted)
console.log(arr)
function Calculator(){
this.methods = {
"-": (a,b) => a-b,
"+": (a,b) => a+b
};
this.calculate = function(str){
let split = str.split(' ');
a = +split[0];
op = split[1];
b = +split[2];
if (!this.methods[op] || isNaN(a) || isNaN(b)){
return NaN;
}
return this.methods[op](a,b);
}
this.addMethod = function(name, func){
this.methods[name] = func;
}
}
let john = { name: "John", surname: "Smith", id: 25 };
let pete = { name: "Pete", surname: "Hunt", id: 30 };
let mary = { name: "Mary", surname: "Key", id: 28 };
users = [ john, pete, mary ];
names = users.map((user) => user.name)
console.log( names ); // John, Pete, Mary
let usersMapped = users.map((user) => {
return {
fullName: user.name + ' ' + user.surname,
id: user.id
}
}
);
console.log(usersMapped[0].id)
console.log(usersMapped[0].fullName)
function sortByAge(arr){
return arr.sort((userA, userB) => userA.id - userB.id)
}
sortByAge(users)
console.log(users[0].name)
console.log(users[1].name)
console.log(users[2].name)
function getAverageAge(arr){
return arr.reduce(function(sum, cur){
sum = sum + cur.id;
},0) / arr.length;
}
console.log(getAverageAge(users))
console.log(camelize("-webkit-translation"))

View File

@ -53,6 +53,3 @@ console.log(arr_s);
console.log(arr_s[0]);
console.log(arr_s[1]);
console.log(arr_s.length);

View File

@ -1,18 +0,0 @@
let map = new Map();
map.set('1', 'first');
map.set(1, 'second');
map.set(true, 'third');
console.log(map.get('1'));
console.log(map.get(1));
console.log(map.get(true));
console.log(map.size);
// we should use the map.get() method, not map[] so that we can use the feature of the map, ot the map can only get the value from number and string
let person = {name: 'John'};
map.set(person, 'hi');
console.log(map.get(person));