• Nov 19, 2022 •CodeCatch
0 likes • 0 views
//JavaScript program to swap two variables //take input from the users let a = prompt('Enter the first variable: '); let b = prompt('Enter the second variable: '); //using destructuring assignment [a, b] = [b, a]; console.log(`The value of a after swapping: ${a}`); console.log(`The value of b after swapping: ${b}`);
• Aug 30, 2024 •C S
1 like • 18 views
# Acronyms ## Computer Numerical Control (CNC) - Typicalldfdfsdffdafdasgfdgfgfdfdafdasfdafda
• Sep 13, 2023 •C S
0 likes • 2 views
/** * @param {number[]} nums * @param {number} target * @return {number[]} */ var twoSum = function(nums, target) { for(let i = 0; i < nums.length; i++) { for(let j = 0; j < nums.length; j++) { if(nums[i] + nums[j] === target && i !== j) { return [i, j] } } } };
• Apr 14, 2023 •Helper
0 likes • 9 views
const quickSort = arr => { const a = [...arr]; if (a.length < 2) return a; const pivotIndex = Math.floor(arr.length / 2); const pivot = a[pivotIndex]; const [lo, hi] = a.reduce( (acc, val, i) => { if (val < pivot || (val === pivot && i != pivotIndex)) { acc[0].push(val); } else if (val > pivot) { acc[1].push(val); } return acc; }, [[], []] ); return [...quickSort(lo), pivot, ...quickSort(hi)]; }; console.log(quickSort([1, 6, 1, 5, 3, 2, 1, 4])) // [1, 1, 1, 2, 3, 4, 5, 6]
• Apr 26, 2025 •hasnaoui1
console.log("xa")
• Nov 16, 2023 •LeifMessinger
0 likes • 7 views
function filePath(file){ let folders = file.getParents(); const parents = []; function makePathString(folderArray){ let path = ""; folderArray.forEach((folder)=>{ path += "/" + folder.getName(); }); return path; } while (folders.hasNext()) { const folder = folders.next(); //This should hopefully remove that folder from the iterator parents.unshift(folder); } return makePathString(parents); } function myFunction() { const myEmail = Session.getEffectiveUser().getEmail(); Logger.log("My email is " + myEmail); // Log the name of every file in the user's Drive. var fileIterator = DriveApp.getFiles(); const files = []; //List of [File, size] entries const filesMaxSize = 10; while (fileIterator.hasNext()) { var file = fileIterator.next(); const owner = file.getOwner(); //Only files I own if((!(owner)) || (!(owner.getEmail)) || owner.getEmail() != myEmail){ continue; } const entry = [file, file.getSize()]; function slideUp(arr, index){ //Let's keep sliding it up so we don't have to sort it at the end. for(let i = index; i > 0; --i){ //Stops at 1 const nextFile = arr[i-1]; if(nextFile[1] > entry[1]){ break; }else{ //Swap with the next file to slide the file up const temp = arr[i]; arr[i] = arr[i - 1]; arr[i - 1] = temp; } } } if(files.length < filesMaxSize){ files.push(entry); slideUp(files, files.length - 1); }else{ if(entry[1] > files[files.length - 1][1]){ //If it's bigger than the smallest file in the list. files[files.length - 1] = entry; //Replace the smallest file slideUp(files, files.length - 1); //Slide it up } } } for(let i = 0; i < filesMaxSize; ++i){ const file = files[i][0]; const size = files[i][1]; Logger.log(size + "\t" + filePath(file) + "/" + file.getName() + "\t" + file.getOwner().getName()); } }