Difference Between Contiguous and Non-Contiguous Memory Allocation

AmitDiwan
Updated on 19-Apr-2021 06:30:11

2K+ Views

In this post, we will understand the difference between contiguous and non-contiguous memory allocation −Contiguous Memory AllocationIn this allocation type, the consecutive blocks of memory is allocated to a file/process.It executes quickly in comparison to non-contiguous memory.It is easy to be controlled by the operating system.Minimum overhead since there are not many address translation when a process is being executed.There is internal fragmentation in contiguous memory allocation.There are different types of partitions: Single partition allocation and multi-partition allocation.Memory gets wasted.The swapped-in process is arranged in the originally allocated space itself.Non-contiguous Memory AllocationIn this type of allocation, separate blocks of memory ... Read More

Difference Between Linker and Loader

AmitDiwan
Updated on 19-Apr-2021 06:07:03

13K+ Views

In this post, we will understand the difference between a linker and a loader −LinkerThe main function of the linker is to generate executable files.The linker takes the input as the object code which would be generated by a compiler/assembler.The process of linking can be understood as a method to combine different snippets of code in order to obtain executable code.There are two types of linkers available: Linkage Editor and Dynamic Linker.Linker also helps combine all the object modules.Linker is responsible to arrange the objects in the program’s address space.LoaderThe main function of a loader is to load executable files ... Read More

Reversing All Alphabetic Characters in JavaScript

AmitDiwan
Updated on 17-Apr-2021 13:45:11

132 Views

ProblemWe are required to write a JavaScript function that takes in a string str. The job of our function is to reverse it, omitting all non-alphabetic characters.ExampleFollowing is the code − Live Democonst str = 'exa13mple'; function reverseLetter(str) {    const res = str.split('')    .reverse()    .filter(val => /[a-zA-Z]/.test(val))    .join('');    return res; }; console.log(reverseLetter(str));Outputelpmaxe

Finding Sum of Sequence Up to a Specified Accuracy Using JavaScript

AmitDiwan
Updated on 17-Apr-2021 13:40:35

172 Views

ProblemSuppose the following sequence:Seq: 1/1 , 1/1x2 , 1/1x2x3 , 1/1x2x3x4 , ....The nth term of this sequence will be −1 / 1*2*3 * ... nWe are required to write a JavaScript function that takes in a number n, and return the sum of first n terms of this sequence.ExampleFollowing is the code − Live Democonst num = 12; const seriesSum = (num = 1) => {    let m = 1;    let n = 1;    for(let i = 2; i < num + 1; i++){       m *= i;       n += (m * -1);    };    return n; }; console.log(seriesSum(num));Output-522956311

Implement Custom Function Like String Prototype Split in JavaScript

AmitDiwan
Updated on 17-Apr-2021 13:39:53

1K+ Views

ProblemWe are required to write a JavaScript function that lives on the prototype object of the String class.It should take in a string separator as the only argument (although the original split function takes two arguments). And our function should return an array of parts of the string separated and split by the separator.ExampleFollowing is the code − Live Democonst str = 'this is some string'; String.prototype.customSplit = (sep = '') => {    const res = [];    let temp = '';    for(let i = 0; i < str.length; i++){       const el = str[i];     ... Read More

Implement Partial Sum Over an Array Using JavaScript

AmitDiwan
Updated on 17-Apr-2021 13:39:29

363 Views

ProblemWe are required to write a JavaScript function that takes in an array of numbers. Our function should construct and return a new array in which each corresponding element is the sum of all the elements right to it (including it) in the input array.ExampleFollowing is the code − Live Democonst arr = [5, 6, 1, 3, 8, 11]; const partialSum = (arr = []) => {    let sum = arr.reduce((acc, val) => acc + val);    const res = [];    let x = 0;    if(arr.length === 0){       return [0];    }    for(let i = 0; i

DivisibleBy Function Over Array in JavaScript

AmitDiwan
Updated on 17-Apr-2021 13:39:03

155 Views

ProblemWe are required to write a JavaScript function that takes in an array of numbers and a single number as two arguments.Our function should filter the array to contain only those numbers that are divisible by the number provided as second argument and return the filtered array.ExampleFollowing is the code − Live Democonst arr = [56, 33, 2, 4, 9, 78, 12, 18]; const num = 3; const divisibleBy = (arr = [], num = 1) => {    const canDivide = (a, b) => a % b === 0;    const res = arr.filter(el => {       return canDivide(el, num);    });    return res; }; console.log(divisibleBy(arr, num));Output[ 33, 9, 78, 12, 18 ]

Inverting Signs of Integers in an Array Using JavaScript

AmitDiwan
Updated on 17-Apr-2021 13:38:36

220 Views

ProblemWe are required to write a JavaScript function that takes in an array of integers (negatives and positives).Our function should convert all positives to negatives and all negatives to positives and return the resulting array.ExampleFollowing is the code − Live Democonst arr = [5, 67, -4, 3, -45, -23, 67, 0]; const invertSigns = (arr = []) => {    const res = [];    for(let i = 0; i < arr.length; i++){       const el = arr[i];       if(+el && el !== 0){          const inverted = el * -1;          res.push(inverted);       }else{          res.push(el);       };    };    return res; }; console.log(invertSigns(arr));Output[ -5, -67, 4, -3, 45, 23, -67, 0 ]

Convert Km/H to Cm/S Using JavaScript

AmitDiwan
Updated on 17-Apr-2021 13:38:13

676 Views

ProblemWe are required to write a JavaScript function that takes in a number that specifies speed in kmph and it should return the equivalent speed in cm/s.ExampleFollowing is the code − Live Democonst kmph = 12; const convertSpeed = (kmph) => {    const secsInHour = 3600;    const centimetersInKilometers = 100000;    const speed = Math.floor((kmph * centimetersInKilometers) / secsInHour);    return `Equivalent in cmps is: ${speed}`; }; console.log(convertSpeed(kmph));OutputEquivalent in cmps is: 333

Binary Array to Corresponding Decimal in JavaScript

AmitDiwan
Updated on 17-Apr-2021 13:37:53

343 Views

ProblemWe are required to write a JavaScript function that takes in a binary array (consisting of only 0 and 1).Our function should first join all the bits in the array and then return the decimal number corresponding to that binary.ExampleFollowing is the code − Live Democonst arr = [1, 0, 1, 1]; const binaryArrayToNumber = arr => {    let num = 0;    for (let i = 0, exponent = 3; i < arr.length; i++) {       if (arr[i]) {          num += Math.pow(2, exponent);       };       exponent--;    };    return num; }; console.log(binaryArrayToNumber(arr));Output11

Advertisements