How Do You Reverse a String?
Steps:
- Create a empty string
newString - Create a for loop, the starting point of the loop with be
str.length - 1which will be the last character of the string - Continue for loop till
iis greater than or equals0, decrementiafter each iteration
function reverseString(str) {
let newString = "";
for(let i = str.length - 1 ; i >= 0; i--) {
newString = newString + str[i];
}
return newString;
}
reverseString('hello');References:
Check if string is anagram?
Steps:
- Pass two strings
wordandanagram - Iterate over first string
word, get character ati - If character present in
anagram, then remove character fromanagram - Iterate until
anagramis empty
function isAnagram(word, anagram) {
if (word.length !== anagram.length) {
return false;
}
for (let i = 0; i < word.length; i++) {
let c = word[i];
let index = anagram.indexOf(c);
if (index === -1) {
return false;
}
anagram = anagram.substring(0, index) + anagram.substring(index + 1, anagram.length);
}
return anagram.length === 0;
}
isAnagram('hello', 'olleh');References:
Margin Collapsing
The top and bottom margins of blocks are sometimes collapsed into a single margin whose size is the largest of the individual margins (or just one of them, if they are equal), a behavior known as margin collapsing.
References:
Difference between ECMAScript and JavaScript
ECMAScript is a language specification and JavaScript is the implementation of that specification.
ECMAScript is standardised by Ecma International.
The Ecma TC39 committee is responsible for evolving the ECMAScript programming language and authoring the specification. Changes to the language are developed by way of process. There are five stages, a strawperson stage, and 4 “maturity” stages. The TC39 committee must approve accetance for each stage.
References:
CSS Box Model
The CSS box model defines how the different parts of a box - margin, border, padding, and content - work together to create a box that can be seen on the page.
Parts of a box
- Content box - The area where content is displayed, which can be sized using properties like width and height.
- Padding box - The padding sits around the content as white space, its size is controlled using padding and related properties.
- Border box - The border box wraps the content and any padding. Its sizing and style can be controlled using border and related properties.
- Margin box - The margin is the outermost layer, wrapping the content, padding and border as whitespace between this box and other elements. Its size can be controlled using margin and related properties.
Standard CSS box model
In the standard box model, if a box is given width and height attribute, this defines the width and height of the content box.
Alternative CSS box model
Using this model, any width is the width of the visible box on the page, therefore the content area width is that the width minux the width for the padding and border.