What do you want to save?
Add Code snippet
New code examples
-
Javascript 2022-01-27 06:01:55
javascript find nearest element
// Find the number from `arr` which is closest to `n` const closest = (arr, n) => arr.reduce((prev, curr) => Math.abs(curr - n) < Math.abs(prev - n) ? curr : prev); // Or const closest = (arr, n) => arr.sort((a, b) => Math.abs(a - n) - Mat... Add solution -
-
Javascript 2022-01-24 03:41:34
Write a shell script that takes two strings as input and determines whether two strings are the anagram.
function isAnagram(stringA, stringB) { // Sanitizing stringA = stringA.toLowerCase().replace(/[\W_]+/g, ""); stringB = stringB.toLowerCase().replace(/[\W_]+/g, ""); // sorting const stringASorted = stringA.split(""... Add solution -
Javascript 2022-01-23 22:11:20
arr.sort
// Sort an array of numbers let numbers = [5, 13, 1, 44, 32, 15, 500] // Lowest to highest let lowestToHighest = numbers.sort((a, b) => a - b); //Output: [1,5,13,15,32,44,500] //Highest to lowest let highestToLowest = numbers.sort((a, b) => b-a);... Add solution
Best helpers
Ranking is empty