// 1. Max Number const maxN = (arr, n = 1) => [...arr].sort((a, b) => b - a).slice(0, n); maxN([1, 2, 3, 4]); // [4] maxN([2, 4, 6, 4, 3], 2); // [6, 4] // 2. Ternary Operator function temparature(temp) { return temp > 39 || temp < 35.5 ? 'Visit Doctor!' : temp < 37.5 && temp > 36.5 ? 'Go Out and Play!!' : temp <= 39 && temp >= 35.5 ? 'Take Some Rest!' : ''; } console.log(temparature(38)); // Take Some Rest! console.log(temparature(36)); // Take Some Rest! console.log(temparature(39.1)); // Visit Doctor! console.log(temparature(35.1)); // Visit Doctor! console.log(temparature(37)); // Go Out and Play // 3. Remove duplicates from an array function removeDuplicates(array) { return [...new Set(array)]; } const uniqueStr = removeDuplicates(['Paul', 'John', 'Harald', 'Paul', 'John']); const uniqueNr = removeDuplicates([1, 1, 2, 2, 3, 3, 4, 5, 6, 7, 7, 7, 9]); console.log(uniqueStr); // [ 'Paul', 'John', 'Harald' ] console.log(uniqueNr); // [1, 2, 3, 4, 5, 6, 7, 9] // 4. Find a specific object in an array const employess = [ { name: 'Paul', job_title: 'Software Engineer' }, { name: 'Peter', job_title: 'Web Developer' }, { name: 'Harald', job_title: 'Screen Designer' }, ]; let sen = employess.find((data) => data.job_title === 'Software Engineer'); console.log(sen); // { name: 'Paul', job_title: 'Software Engineer' } // 5. Decapitalize const decapitalize = ([first, ...rest]) => first.toLowerCase() + rest.join(''); decapitalize('CamelCase'); // camelCase decapitalize('Super'); // super // 6. Reverse a String const reverse = (input) => { return input.split('').reverse().join(''); }; console.log(reverse('Paul Knulst')); // tslunK luaP console.log(reverse('Twitter is awesome')); // emosewa si rettiwT // 7. Calculate the Day of the Year const dayOfYear = (date) => Math.floor( (date - new Date(date.getFullYear(), 0, 0)) / 1000 / 60 / 60 / 24 ); dayOfYear(new Date()); // 350 // 8. Convert an array to an HTML list element const arrayToHtmlList = (arr, listID) => ((el) => ( (el = document.querySelector('#' + listID)), (el.innerHTML += arr.map((item) => `