Skip to main content

Posts

动物们的迷惑行为,你能忍住不笑吗?

人类们的尴尬瞬间,你能忍住不笑吗?

大内密探零零发中的金像奖戏份

About the Little Lemon receipt maker exercise

 My homework and exercise of the lesson "About the Little Lemon receipt maker exercise" of the class "programming with Javascript" on coursera. const menu = [     {         Dish : "Italian pasta" ,         price : 9.55     },     {         Dish : "Rice with veggies" ,         price : 8.65     },     {         Dish : "Chicken with potatoes" ,         price : 15.55     },     {         Dish : "Vegetarian Pizza" ,         price : 6.45     } ]; function receiptMaker ( arr , bool ) {     if ( bool == false )     {         console . log ( "Prices without tax:" );         arr . forEach ( element => {             console . log ( `Dish: ${ element . Dish } Price (incl.tax):$ ${ element . price } ` );                     });     }     else     {         console . log ( "Prices with 20% tax:" );         arr . forEach ( element => {             console . log ( `Dish: ${ element . Dish } Price (inc

Write a React Component from Scratch

  // Change code below this line class   MyComponent   extends   React . Component  {    constructor ( props ) {      super ( props );   }    render () {      return  (        // The JSX code you put here is what your component will render       < div >< h1 > My   First   React   Component !</ h1 ></ div >     );   } }; ReactDOM . render (< MyComponent  />, document . getElementById ( 'challenge-node' ));

Palindrome Checker回文检查

 Return true if the given string is a palindrome. Otherwise, return false. A palindrome is a word or sentence that's spelled the same way both forward and backward, ignoring punctuation, case, and spacing. Note: You'll need to remove all non-alphanumeric characters (punctuation, spaces and symbols) and turn everything into the same case (lower or upper case) in order to check for palindromes. 主要思路是,把字符串转换为一个数组,然里利用数组的reverse()方法,得到一个新的数组,这个新的数组再合成字符串,和原来的字符串进行比较。 function   palindrome ( str ) {    var   pattern  =  /[^a-z0-9A-Z]/ gi ;    var   newstr  =  str . replace ( pattern , "" ). toLowerCase ();    console . log ( newstr );    var   newarr  =  newstr . split ( "" ). reverse ();    console . log ( newarr );    var   reversedStr  =  newarr . join ( "" );    console . log ( reversedStr );    if  ( reversedStr == newstr )   {      return   true ;   }     return   false ; } palindrome ( "eye" );

Sum All Numbers in a Range

 We'll pass you an array of two numbers. Return the sum of those two numbers plus the sum of all the numbers between them. The lowest number will not always come first. For example, sumAll([4,1]) should return 10 because sum of all the numbers between 1 and 4 (both inclusive) is 10. 解决的思路如下: function   sumAll ( arr ) {    var   big ;    var   small ;    var   sum  = 0 ;    if ( arr [ 0 ]>= arr [ 1 ])   {      big  =  arr [ 0 ];      small  =  arr [ 1 ];   }    else {      big  =  arr [ 1 ];      small  =  arr [ 0 ];   }    for  ( let   i  =  small ; i <= big ; i ++)   {      sum += i ;   }    return   sum ; } console . log ( sumAll ([ 1 ,  4 ])); sumAll ([ 1 ,  4 ]);