What do you want to save?
Add Code snippet
New code examples
-
Javascript 2021-09-21 00:29:02
set and get array inside cookie in javascript
JSON encode it, effectively producing a string like "{name:'myname',age:'myage'}" which you put in a cookie, retrieve when needed and decode back into a JavaScript array/object. Example - store array in a cookie: ------------------------------... Add solution -
Javascript 2021-09-20 23:30:03
Convert a string to numbers in an array and define by even and odd values
// Convert a string to numbers in an array and define by even and odd values function reverseOdd(str) { let odd = []; let even = []; let arrayStr = str.split(" ").map(function(element){return element.length;}); for (var i = 0; i < array... Add solution -
Javascript 2021-09-20 20:44:03
string reduction javascript
// method to extend String to call reduce the same way as an Array String.prototype.reduce = function () { return this.split().reduce(...arguments); } // sum of the ascii codes using the newly created String prototype method str.reduce((a,b) => a... Add solution -
Javascript 2021-09-20 18:42:04
javascript sum of all the multiples of 3 or 5 below 1000 running total
(() => { // sum35 :: Int -> Int const sum35 = n => { // The sum of all positive multiples of // 3 or 5 below n. const f = sumMults(n); return f(3) + f(5) - f(15); }; // sumMults ... Add solution -
Javascript 2021-09-20 16:39:02
javascript rest parameters vs spread operator
/** * JS Spread and Rest operators: * Two operators with the same syntax (...) but behave differently */ // Rest parameter: collects all remaining elements into an array. function foo (...args) { console.log(args) } foo(1,2,3,4,5,6) // Output: (6) [1,... Add solution -
C# 2021-09-20 16:37:02
jagged array c#
// A "multidimensional array" is essentially a matrix occupying one block of memory // The "jagged array" is an array of arrays // - with no restriction that the latter arrays need to be of the same dimension/length // - each of the... Add solution -
PHP 2021-09-20 14:28:01
forPage return keys on page 2
// On pages >= 2, the keys are returned since forPage returns an array with keys // To fix this, just chain values() method. $items_per_page = 10; $current_page = LengthAwarePaginator::resolveCurrentPage(); $paginated_response = new LengthAwarePaginato... Add solution -
PHP 2021-09-20 12:26:02
lengthawarepaginator gives keys on page 2
// On pages >= 2, the keys are returned since forPage returns an array with keys // To fix this, just chain values() method. $items_per_page = 10; $current_page = LengthAwarePaginator::resolveCurrentPage(); $paginated_response = new LengthAwarePaginato... Add solution -
C 2021-09-20 11:36:02
Complete the function in the editor. It has one parameter: an array, . It must iterate through the array performing one of the following actions on each element:
/* * Modify and return the array so that all even elements are doubled and all odd elements are tripled. * * Parameter(s): * nums: An array of numbers. */ function modifyArray(nums) { return (nums || []).map(num => num * (num % 2 === 0 ? 2 : ... Add solution -
Other 2021-09-19 21:00:02
construct binary tree from array
When implementing a binary tree as an array it helps to have a clear visualization of how the two representations mirror one another, and review the mathematical structure that underlines the relationship. If we consider 0-indexed arrays the mathematical... Add solution
Best helpers
Ranking is empty