• Aug 13, 2023 •CAS
1 like • 2 views
function sortNumbers(arr) { return arr.slice().sort((a, b) => a - b); } const unsortedArray = [4, 1, 9, 6, 3, 5]; const sortedArray = sortNumbers(unsortedArray); console.log("Unsorted Numbers:", unsortedArray); console.log("\n"); console.log("Sorted Numbers:", sortedArray);
• Nov 18, 2022 •AustinLeath
0 likes • 2 views
var d = new Date(); var d = new Date(milliseconds); var d = new Date(dateString); var d = new Date(year, month, day, hours, minutes, seconds, milliseconds);
• Nov 19, 2022 •CodeCatch
0 likes • 0 views
const head = arr => (arr && arr.length ? arr[0] : undefined); head([1, 2, 3]); // 1 head([]); // undefined head(null); // undefined head(undefined); // undefined
• Mar 9, 2021 •LeifMessinger
0 likes • 1 view
alert("bruh")
const countSubstrings = (str, searchValue) => { let count = 0, i = 0; while (true) { const r = str.indexOf(searchValue, i); if (r !== -1) [count, i] = [count + 1, r + 1]; else return count; } }; countSubstrings('tiktok tok tok tik tok tik', 'tik'); // 3 countSubstrings('tutut tut tut', 'tut'); // 4
function formatDate(date) { return date.toLocaleDateString(); } function Comment(props) { return ( <div className="Comment"> <div className="UserInfo"> <img className="Avatar" src={props.author.avatarUrl} alt={props.author.name} /> <div className="UserInfo-name"> {props.author.name} </div> </div> <div className="Comment-text">{props.text}</div> <div className="Comment-date"> {formatDate(props.date)} </div> </div> ); } const comment = { date: new Date(), text: 'I hope you enjoy learning React!', author: { name: 'Hello Kitty', avatarUrl: 'https://placekitten.com/g/64/64', }, }; ReactDOM.render( <Comment date={comment.date} text={comment.text} author={comment.author} />, document.getElementById('root') );